Static & default routes
Configure static and default routes so two remote networks can reach each other.
By Invicly Tech, , in Computer Networking. About 13 minutes to read.
In short
Static routes are entered by hand and never change unless you change them. They are simple and predictable for small networks, stub sites and default routes towards an ISP. Their weakness is that they do not adapt when links fail.
Explained simply
A static route is a line you type into a router's table by hand: "to reach network X, send packets to neighbour Y". It stays exactly as you typed it until you change it. The router never learns it, checks it or updates it on its own.
Static routes are perfect for small, simple setups. A branch office with one internet link needs just one: a default route pointing at the ISP. Two small offices joined by one link need one route on each side.
The catch is that static routes do not react to problems. If a link far away breaks, the static route still points that way, and traffic disappears into a black hole. And in a big network, you would have to type and maintain hundreds of routes on every router.
The most common mistake is forgetting that traffic must come back. If router A knows how to reach network B, but router B does not know how to reach network A, your ping goes out fine and the replies are lost.
Press Play on a diagram to walk through it one step at a time.
- 1LAN A 10.1.0.0/24
Hosts use R1 as gateway.
- 2R1
ip route 10.2.0.0/24 via 172.16.0.2
- 3Link 172.16.0.0/30
Point-to-point between routers.
- 4R2
ip route 10.1.0.0/24 via 172.16.0.1
- 5LAN B 10.2.0.0/24
Hosts use R2 as gateway.
- 1Plan both directions
Forward and return route on every hop.
- 2Check the next hop
It must be directly reachable.
- 3Add the route
ip route on Cisco, ip route add on Linux.
- 4Verify the lookup
show ip route x or ip route get x.
- 5Test end to end
Ping and traceroute from a host.
- 6Make it permanent
Save config, netplan or nmcli.
In depth
Three ways to write a static route
On Cisco IOS the format is ip route NETWORK MASK NEXT-HOP-OR-INTERFACE [DISTANCE]. With a next-hop IP, such as ip route 10.2.0.0 255.255.255.0 172.16.0.2, the router does a second lookup to find how to reach 172.16.0.2 (a recursive lookup). With only an exit interface, such as ip route 10.2.0.0 255.255.255.0 Serial0/0, it treats the network as directly attached. That is fine on point-to-point links, but on Ethernet the router must ARP for every single destination and relies on the neighbour answering for them (proxy ARP). The fully specified form gives both: ip route 10.2.0.0 255.255.255.0 GigabitEthernet0/1 172.16.0.2.
The default distance is 1. Adding a number at the end, such as 250, makes it a floating static route: it only appears in the table when every better route to the same prefix is gone.
- Next hop IP: recursive lookup
- Exit interface only: OK on point-to-point links
- Both: clearest on Ethernet
- Distance at the end makes it a backup
When a static route disappears, and when it does not
A static route is removed from the table when its exit interface goes down, or when the next hop can no longer be reached through any route. That covers a cable unplugged from the router itself.
It does not cover a failure further away. If the next hop router is still up but its own uplink to the ISP is dead, your router keeps sending traffic there, and it is silently dropped. Floating backups only help if the main route actually leaves the table.
Cisco solves this with IP SLA and object tracking: the router pings a target beyond the link and removes the route when the pings fail. Dynamic routing protocols solve it naturally, because they detect lost neighbours and recalculate. Linux is similar: a route stays while its interface is up, whatever lies beyond the next hop, and by default even a cable losing carrier only marks the route linkdown.
- Exit interface goes down
- Cable unplugged at this router
- Next hop no longer reachable by any route
- Next hop router's uplink fails
- A link two hops away breaks
- Next hop is up but misconfigured
Static routes on Linux
ip route add 10.2.0.0/24 via 172.16.0.2 dev eth0 adds a route, ip route del removes it, and ip route replace adds or overwrites in one step, which is handy in scripts. ip route add default via 192.168.1.1 sets the default gateway. ip route add blackhole 10.9.0.0/16 silently drops traffic to a range.
These commands change only the running kernel and are lost on reboot. To make them permanent, put them in your network configuration. With netplan (Ubuntu), add a routes list under the interface with to: 10.2.0.0/24 and via: 172.16.0.2. With NetworkManager, run nmcli connection modify eth0 +ipv4.routes "10.2.0.0/24 172.16.0.2" and bring the connection up again.
If the Linux box should forward packets between interfaces, enable forwarding: sysctl -w net.ipv4.ip_forward=1, and save it in a file under /etc/sysctl.d/ so it survives reboots.
- ip route replace is idempotent: safe to run twice
- Routes from ip route add vanish on reboot
- Forwarding is off by default on most distributions
Troubleshooting a missing return route
The classic symptom: from LAN A you ping a host in LAN B and get timeouts, yet the far router's interface answers. Work in both directions. On the far host, run tcpdump -ni eth0 icmp. If echo requests arrive and replies leave, the forward path is fine and the reply is lost on the way back. Then check, router by router, whether each one has a route to LAN A: show ip route 10.1.0.5 on Cisco or ip route get 10.1.0.5 on Linux.
Often the far router has no route back and sends the reply to its own default route, usually the ISP, which drops private addresses. A second cause on Linux is reverse path filtering. With net.ipv4.conf.all.rp_filter=1 (strict mode), the kernel drops packets that arrive on an interface it would not use to reply, which breaks asymmetric paths. Setting 2 (loose mode) only checks that some route back exists.
- Host A 10.1.0.5 to R1: Echo request to 10.2.0.91Echo request to 10.2.0.9
- R1 to R2: R1 has a route to 10.2.0.0/242R1 has a route to 10.2.0.0/24
- R2 to Host B 10.2.0.9: Delivered on LAN B3Delivered on LAN B
- Host B 10.2.0.9 to R2: Echo reply to 10.1.0.54Echo reply to 10.1.0.5
- 5No route to 10.1.0.0/24: reply lostR2 to R2: No route to 10.1.0.0/24: reply lost
Summaries, null routes and when to stop using static
You can cover many networks with one summary route. If a branch uses 10.2.0.0/24 to 10.2.3.0/24, one route to 10.2.0.0/22 replaces four. On the branch router, add ip route 10.2.0.0 255.255.252.0 Null0 too. Null0 is a discard interface: traffic for an unused part of the summary is dropped there instead of following the default route back to headquarters and looping until the TTL runs out. More specific routes still win, so the real subnets keep working.
Static routing scales badly. Every router needs a route to every network it is not connected to, in both directions, and every change means editing several devices by hand. A good rule: static for stub sites, default routes and a few fixed paths; a dynamic protocol such as OSPF once you have several routers or more than one path. Cloud route tables, such as those in a VPC, are static routes too, and follow the same longest-prefix rules.
Learn it in 4 short steps
About 30m each. Track them with a timer in your plan.
- 1Configure static routes on routers~30m
- 2Add a default route~30m
- 3Add a static route on Linux~30m
- 4Troubleshoot missing return routes~30m
Key points
- Every router on the path needs a route in both directions.
- A floating static route has a higher distance and acts as a backup.
- Static routes scale poorly beyond a handful of routers.
- Linux static routes are added with ip route add.
Key terms
Tap a card to flip it. 0/3 known
Examples
! Cisco IOS on R1
ip route 10.2.0.0 255.255.255.0 172.16.0.2
ip route 0.0.0.0 0.0.0.0 203.0.113.1
# Linux equivalent
sudo ip route add 10.2.0.0/24 via 172.16.0.2Two offices with an ISP and a backup LTE link
R1 (office A, 10.1.0.0/24) connects to R2 (office B, 10.2.0.0/24) over 172.16.0.0/30. R1 also has the internet uplink. Step 1: on R1, a route to LAN B via R2, a default route to the ISP, and a floating default with distance 250 via an LTE router, used only if the main uplink interface goes down. Step 2: on R2, a route back to LAN A and a default route via R1, so office B also reaches the internet. Step 3: verify with show ip route static and a sourced ping, which tests the return path too.
! R1
ip route 10.2.0.0 255.255.255.0 172.16.0.2
ip route 0.0.0.0 0.0.0.0 203.0.113.1
ip route 0.0.0.0 0.0.0.0 198.51.100.1 250
! R2
ip route 10.1.0.0 255.255.255.0 172.16.0.1
ip route 0.0.0.0 0.0.0.0 172.16.0.1
! verify on R1
show ip route static
ping 10.2.0.10 source 10.1.0.1A Linux server as a router to a lab network
A Linux box has eth0 on the office LAN and eth1 on 192.168.50.0/24, where another router at 192.168.50.2 leads to a lab network 10.3.0.0/24. Step 1: enable forwarding now and on every boot. Step 2: add the route to the lab with ip route replace, so the script is safe to rerun. Step 3: check the lookup with ip route get. Step 4: remember the office routers and the lab router also need routes pointing back through this box, or replies will be lost.
sudo sysctl -w net.ipv4.ip_forward=1
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-forward.conf
sudo ip route replace 10.3.0.0/24 via 192.168.50.2 dev eth1
ip route get 10.3.0.20
# 10.3.0.20 via 192.168.50.2 dev eth1 src 192.168.50.1 uid 1000
ping -c 3 10.3.0.20Quick reference
- Cisco: ip route 10.2.0.0 255.255.255.0 172.16.0.2; default: ip route 0.0.0.0 0.0.0.0 NEXT-HOP
- Floating static: add a distance, e.g. ip route 0.0.0.0 0.0.0.0 198.51.100.1 250
- Linux: ip route add 10.2.0.0/24 via 172.16.0.2 dev eth0; ip route replace is safe to rerun
- Linux routes added by hand vanish on reboot: use netplan or nmcli to persist them
- Enable forwarding: sysctl -w net.ipv4.ip_forward=1 and save it under /etc/sysctl.d/
- A summary route plus a Null0 (or blackhole) route prevents loops for unused subnets
- Ping works one way only? Check the return route on every router, then rp_filter
Common mistakes
- Configuring only the forward route, so replies never return.
- Pointing a static route at a next hop that is not directly reachable.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write the Cisco and Linux commands for: (a) a route to 192.168.20.0/24 via 10.0.0.2, (b) a default route via 10.0.0.1.
- Exercise 2medium
Three routers in a line: LAN1 10.1.0.0/24 - R1 - 172.16.12.0/30 - R2 - 172.16.23.0/30 - R3 - LAN3 10.3.0.0/24. R1 uses .1 on its link to R2, R2 uses .2 and .5 (to R3), R3 uses .6. List every static route needed so LAN1 and LAN3 can talk.
- Exercise 3hard
A Linux router has two uplinks: eth0 via 203.0.113.1 (main) and eth1 via 198.51.100.1 (backup). Make the backup take over when eth0's link goes down, and explain why it will not take over if only the ISP behind eth0 fails.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- When should I use static routing instead of OSPF?
- For small or stub networks with one exit, for default routes to an ISP, and for a few fixed paths. Once you have several routers or redundant links, a dynamic protocol saves work and reacts to failures.
- What is a floating static route?
- A static route with a higher administrative distance than the main route for the same prefix. It stays hidden and only enters the table when the main route disappears.
- Why can I ping the far router but not the hosts behind it?
- The far router answers from its own interface, but the hosts' replies need a route back to you on every router along their path. Usually one router is missing that return route, or the hosts have the wrong default gateway.