Static Routing (Static Routes)
Static routes are routes configured manually by an administrator that do not change automatically when the network topology changes.
Overview
Static routing is used when:
- The network topology is simple
- Routes are predictable
- Resource requirements are minimal
- Full control over routing is required
- There is no need for automatic adaptation
Advantages:
- Simple configuration
- Predictable behavior
- No routing protocol overhead
- Full control
- Security (no dynamic exchange)
Disadvantages:
- Manual management
- No automatic failover
- Does not scale for large networks
- Requires manual updates when things change
IPv4 static routes
Basic route
A route with a next-hop address:
set protocols static route 192.168.2.0/24 next-hop 10.0.0.2
commitSyntax:
set protocols static route <network/prefix> next-hop <IP-address>Route via interface
When the next-hop is in a directly connected network:
set protocols static route 192.168.3.0/24 interface eth1
commitUseful for point-to-point links.
Default route
Default gateway (0.0.0.0/0):
set protocols static route 0.0.0.0/0 next-hop 192.0.2.1
commitAll traffic that does not match any other route will go through this next-hop.
Multiple next-hops
Load balancing across multiple paths:
set protocols static route 192.168.10.0/24 next-hop 10.0.0.2
set protocols static route 192.168.10.0/24 next-hop 10.0.0.3
commitTraffic will be distributed between both next-hops (ECMP - Equal-Cost Multi-Path).
Administrative Distance
The priority of a route when the same network is learned from multiple sources.
Setting the distance
set protocols static route 192.168.5.0/24 next-hop 10.0.0.2 distance 10
commitValues:
- 1 - default for static routes
- 1-255 - valid range
- 255 - route disabled
Floating Static Route
A backup route with a higher distance:
# Primary route (via OSPF, AD=110)
set protocols ospf ...
# Backup static route
set protocols static route 192.168.20.0/24 next-hop 10.0.0.10 distance 120
commitThe static route is activated only if the OSPF route disappears.
Blackhole Routes
Routes that silently drop packets (no ICMP).
set protocols static route 192.168.100.0/24 blackhole
commitUsed for:
- Preventing routing loops
- Security (blocking unwanted traffic)
- Route aggregation
Blackhole with distance
set protocols static route 10.0.0.0/8 blackhole distance 200
commitReject Routes
Routes that reject packets by sending an ICMP unreachable message.
set protocols static route 172.16.0.0/12 reject
commitDifference from blackhole:
- blackhole - drops silently (no ICMP)
- reject - sends ICMP destination unreachable
BFD Support
Bidirectional Forwarding Detection for fast detection of next-hop failures.
Enabling BFD
set protocols static route 192.168.30.0/24 next-hop 10.0.0.5 bfd
commitThe BFD session monitors next-hop reachability and automatically removes the route on failure.
Configuring a BFD profile
set protocols bfd profile static-routes interval transmit 300
set protocols bfd profile static-routes interval receive 300
set protocols bfd profile static-routes interval multiplier 3
set protocols static route 192.168.40.0/24 next-hop 10.0.0.6 bfd profile static-routes
commitBFD parameters:
- transmit - transmit interval (ms)
- receive - receive interval (ms)
- multiplier - number of missed packets before declaring the session down
Disable Route
Temporarily disabling a route without removing its configuration:
set protocols static route 192.168.50.0/24 next-hop 10.0.0.7 disable
commitIPv6 static routes
Basic IPv6 route
set protocols static route6 2001:db8:2::/64 next-hop 2001:db8:1::2
commitIPv6 route via interface
set protocols static route6 2001:db8:3::/64 interface eth1
commitIPv6 default route
set protocols static route6 ::/0 next-hop 2001:db8:1::1
commitIPv6 blackhole
set protocols static route6 2001:db8:100::/48 blackhole
commitRouting Tables and VRF
Static routes in alternative routing tables (VRF).
Route in a VRF
set vrf name MGMT table 100
set protocols static route 192.168.99.0/24 interface eth2 vrf MGMT
commitVerifying routes in a VRF
show ip route vrf MGMTConfiguration examples
Simple network with two locations
Topology:
[Site A] ---- 10.0.0.0/30 ---- [Site B]
192.168.1.0/24 192.168.2.0/24Site A configuration:
set protocols static route 192.168.2.0/24 next-hop 10.0.0.2
commitSite B configuration:
set protocols static route 192.168.1.0/24 next-hop 10.0.0.1
commitDefault route to an ISP
set protocols static route 0.0.0.0/0 next-hop 203.0.113.1
set protocols static route 0.0.0.0/0 description 'Default route to ISP'
commitDual ISP with failover
Topology:
ISP1 (primary)
|
VyOS Router
|
ISP2 (backup)Configuration:
# Primary ISP (lower distance)
set protocols static route 0.0.0.0/0 next-hop 198.51.100.1 distance 10
# Backup ISP (higher distance)
set protocols static route 0.0.0.0/0 next-hop 203.0.113.1 distance 20
commitThe backup route is activated only when the primary is unavailable.
Load balancing across two links
set protocols static route 0.0.0.0/0 next-hop 198.51.100.1
set protocols static route 0.0.0.0/0 next-hop 203.0.113.1
commitTraffic is distributed between both next-hops (ECMP).
Blackhole for security
Blocking access to the internal management network from the DMZ:
set protocols static route 192.168.99.0/24 blackhole
commitVPN site-to-site routes
After setting up a VPN tunnel (for example, WireGuard):
set protocols static route 192.168.10.0/24 interface wg0
set protocols static route 192.168.20.0/24 interface wg0
commitAggregate route with blackhole
Advertise an aggregated prefix, using a blackhole for non-existent subnets:
# Aggregate
set protocols static route 10.0.0.0/16 blackhole distance 200
# Specific subnets
set protocols static route 10.0.1.0/24 next-hop 10.1.1.1
set protocols static route 10.0.2.0/24 next-hop 10.1.1.2
commitA blackhole with a high distance is not activated as long as more specific routes exist.
Multi-site hub-and-spoke
Hub configuration:
# Routes to spokes
set protocols static route 192.168.10.0/24 next-hop 10.10.0.10
set protocols static route 192.168.20.0/24 next-hop 10.10.0.20
set protocols static route 192.168.30.0/24 next-hop 10.10.0.30
commitSpoke configuration (for example, Spoke1):
# Default to hub
set protocols static route 0.0.0.0/0 next-hop 10.10.0.1
# Specific routes to other spokes (optional)
set protocols static route 192.168.20.0/24 next-hop 10.10.0.1
set protocols static route 192.168.30.0/24 next-hop 10.10.0.1
commitOperational commands
Viewing the routing table
All routes:
show ip routeStatic routes only:
show ip route staticA specific network:
show ip route 192.168.1.0/24IPv6:
show ipv6 route
show ipv6 route staticRoute details
show ip route 192.168.1.0/24 detailStatistics
show ip route summaryConnectivity check
ping 192.168.2.1
traceroute 192.168.2.1Ping with a source-address:
ping 192.168.2.1 source-address 192.168.1.1Troubleshooting
Route does not appear in the table
Check the configuration:
show configuration commands | grep staticCheck next-hop reachability:
ping <next-hop-IP>Check interface status:
show interfacesTraffic does not pass
Check the route:
show ip route <destination>Traceroute:
traceroute <destination>Check the firewall:
show firewallCheck NAT (if applicable):
show nat source rulesECMP does not balance
Make sure both next-hops have the same distance:
show ip route staticVerify that both paths are active:
show ip route <network> detailFloating route does not activate
Check the distance:
show ip route <network> detailMake sure the floating route’s distance is higher than that of the primary route.
Integration with dynamic protocols
Redistribute static into OSPF
set protocols ospf redistribute static
commitRedistribute static into BGP
set protocols bgp system-as 65001
set protocols bgp redistribute static
commitRoute-map for selective redistribution
set policy route-map STATIC-TO-OSPF rule 10 action permit
set policy route-map STATIC-TO-OSPF rule 10 match ip address prefix-list ALLOWED-PREFIXES
set protocols ospf redistribute static route-map STATIC-TO-OSPF
commitBest practices
- Document your routes - use description
- Use distance - for failover scenarios
- Plan IP addressing - prefix summarization
- Test failover - verify backup routes
- Monitoring - track next-hop status
- BFD - for fast failure detection
- Backup - save your configuration
- Avoid loops - check route symmetry
- Route aggregation - use blackhole routes
- Logging - document changes
When to use static routes
Suitable for:
- Small networks (< 5 routers)
- Stub networks (a single exit only)
- Default routes
- Host routes
- VPN site-to-site
- Lab/test environments
Not suitable for:
- Large networks (> 10 routers)
- Frequent topology changes
- Automatic failover requirements
- Mesh topologies
- When fast convergence is needed
Migrating to dynamic routing
As the network grows, a transition to dynamic routing may be required.
Gradual migration
- Run a dynamic protocol in parallel
- Use distance to control preferences
- Gradually remove the static routes
- Test at each stage
Hybrid approach
A combination of static and dynamic routes:
- Static for stub sites
- Dynamic (OSPF/BGP) for the core
- Redistribute static into the dynamic protocol