Sub topic 4
The default route as a catch-all
This chapter assumes you know CIDR prefix notation and how longest-prefix match picks the most specific route. You should also be able to type commands on a router or Linux host.
What the default route is
A default route is a routing table entry whose prefix is 0.0.0.0/0. A /0 prefix has zero fixed bits, so it matches every IPv4 destination. Because longest-prefix match prefers longer prefixes, the default route is the least specific entry possible. The router uses it only when no other route matches.
Most hosts and edge routers do not need to know every network on the Internet. They know their own networks, and they send everything else to one upstream router. That router is the next hop of the default route. Cisco documentation calls it the "gateway of last resort."
Configuring a default route
On a Linux host or router:
# Send all traffic with no more specific route to 192.168.1.1
sudo ip route add default via 192.168.1.1 dev eth0
# Confirm the entry and see which route a public address would use
ip route show
ip route get 8.8.8.8On Cisco IOS:
! Default route toward the upstream router
ip route 0.0.0.0 0.0.0.0 192.168.1.1The mask 0.0.0.0 means no bits must match. The next hop must be reachable through a connected network, or the router cannot use the route.
How it fits into the lookup
Suppose a router has these routes:
| Prefix | Next hop |
|---|---|
| 10.1.0.0/16 | connected |
| 10.2.0.0/16 | 192.168.1.2 |
| 0.0.0.0/0 | 192.168.1.1 |
A packet for 10.2.5.7 matches 10.2.0.0/16 and 0.0.0.0/0. The /16 is longer, so it wins. A packet for 203.0.113.9 matches only the default route, so it goes to 192.168.1.1.
Where defaults are used
- Stub networks. A branch office with one uplink needs only its local networks and a default route to headquarters.
- Internet edge. A company router points a default route at its ISP.
- Dynamic routing. A router can learn a default route from a protocol. It can also hold a static default and advertise it to neighbors, so interior routers need no static entry of their own.
Common errors
- No default route. Local and specifically routed destinations work, but everything else fails. On Cisco,
show ip routeshows "Gateway of last resort is not set." - Wrong or unreachable next hop. The entry exists, but traffic goes nowhere. Check that the next hop is on a connected subnet and responds.
- Default routes in both directions. If router A defaults to B and B defaults to A, a packet for an unknown destination loops until its TTL expires. Point defaults toward the upstream side only.
- Hiding failures. A default route sends traffic for nonexistent networks upstream instead of dropping it locally. This makes some faults harder to spot.
Exercise
A router has routes for 10.0.0.0/8 via R1, 10.5.0.0/16 via R2, and 0.0.0.0/0 via R3. Which next hop does it use for 10.5.9.1, for 10.200.1.1, and for 172.16.0.1?
Show answer
10.5.9.1 goes to R2, because /16 is the longest matching prefix. 10.200.1.1 goes to R1, because only the /8 and the default match, and /8 is longer. 172.16.0.1 goes to R3, because only the default route matches.