Sub topic 4
The default route as a catch-all
This chapter assumes you know CIDR prefix notation, the difference between a router, a switch and a host, and basic command-line use on a Linux host or a Cisco IOS router. It also assumes you have seen longest-prefix match, where the most specific matching route wins.
What a default route is
A default route is a routing table entry whose prefix is 0.0.0.0/0 in IPv4 (::/0 in IPv6). A prefix length of 0 means no bits of the destination address need to match, so every address matches this entry.
Longest-prefix match prefers the entry with the longest prefix, and /0 is the shortest possible. The default route is therefore the route of last resort. It is used only when no other entry matches. Adding it never changes how traffic to a more specific destination is forwarded.
The default route is a special case of a static route, but dynamic protocols can also learn or originate one. Its job is to answer the question "where do I send traffic for destinations I know nothing about?" without listing every destination on the Internet.
Why it exists
Most devices sit at the edge of the part of the network they understand. A branch router knows its own LANs and the path to headquarters. It has no reason to know the 900,000 or so prefixes in the global Internet table. A single default route toward the upstream provider covers all of them with one line.
The same logic applies to hosts. A laptop with address 192.168.1.50/24 has a connected route for 192.168.1.0/24 and one default route to its gateway. Everything off the local subnet goes to the gateway.
The trade-off is that the router stops being the authority on what is reachable. With a default route, a packet to a nonexistent destination is still forwarded upstream instead of being dropped locally. The router can no longer say "no route to host" for that case. The upstream device has to discard it.
Configuring a default route
On a Linux host or router, you can set the default with the default keyword. It is equivalent to 0.0.0.0/0.
# Add a default route via the upstream router
sudo ip route add default via 192.168.1.1 dev eth0
# Show the table; the default entry appears as "default via ..."
ip route show
# Ask the kernel which route it would use for an address with no specific match
ip route get 8.8.8.8On Cisco IOS, the default route is a static route with an all-zero destination and mask. The next hop can be an IP address.
! Cisco IOS: default route toward the upstream router
ip route 0.0.0.0 0.0.0.0 192.168.1.1
! Verify: the default route is marked with S* in the table
show ip routeIn show ip route output, S* means a static route that is a candidate default. The line "Gateway of last resort is 192.168.1.1 to network 0.0.0.0" appears above the table once a default exists. If it says "Gateway of last resort is not set", the router has no catch-all.
Next hop address versus exit interface
You can point a static route at an exit interface instead of a next-hop address. On a point-to-point serial link this works well. On a multi-access network such as Ethernet it is a problem. The router then treats every destination as directly attached to that interface and sends an ARP request for each one. This burdens the ARP cache and works only if a neighbor answers with proxy ARP. On Ethernet, give the next-hop IP address. Specifying both the interface and the next hop is also valid and removes the ambiguity.
Recursive lookup
When the next hop is an IP address, the router must resolve it. It performs a second lookup for 192.168.1.1 and finds a connected route, which gives it the exit interface. If that connected route disappears, for example because the interface goes down, the static route that depends on it is removed from the table. This is how a static route "fails" without any protocol: its next hop becomes unreachable.
How the lookup uses it
The diagram shows the forwarding decision for one packet.
The practical effect: with a default route, the last branch is never reached for IPv4 destinations, because /0 matches everything. Destination-unreachable messages from your router become rare. Errors move to the upstream devices.
Default routes and dynamic protocols
A default route does not have to be static. There are three common ways it enters a table.
- Static on the edge, learned elsewhere. An edge router has a static default to the ISP. It then advertises that default to the inner routers through a routing protocol. The inner routers learn it dynamically and need no static configuration.
- Received from a provider. With BGP, an ISP can send a customer a default route in place of the full Internet table.
- DHCP. Hosts usually receive their default gateway from a DHCP server.
On Cisco IOS, OSPF only advertises a default if you tell it to:
! Edge router: static default to ISP, then advertise it into OSPF
ip route 0.0.0.0 0.0.0.0 203.0.113.1
router ospf 1
default-information originateBy default, default-information originate advertises the default only if the router already has one in its own table. If that static route is removed, OSPF withdraws the advertisement. This is the behavior you usually want, because a router that has lost its upstream should not attract traffic. Adding the always keyword advertises the default regardless, which can create a blackhole during an outage.
Administrative distance still applies. A static default has distance 1. If the same router also learns a default from OSPF (110), the static one wins. To make a static default a backup, raise its distance, as in a floating static route.
Common problems
Routing loops from mismatched defaults
Suppose router A has a default route pointing to router B, and B has a default route pointing back to A. A packet for an unknown destination goes A, B, A, B, and so on. Each pass decrements the TTL (time to live) field, and the packet is dropped when it reaches zero, with an ICMP "time exceeded" message sent to the source. The defaults should point toward the exit, never at each other. Check this when traceroute shows two addresses alternating.
Multiple defaults
A host or router can have more than one default route, but only one is used unless equal-cost multipath is active. On Linux, two defaults with different metrics can coexist. The one with the lower metric is preferred, and the other is a backup.
# Primary default via eth0, backup via wlan0 with a higher metric
sudo ip route add default via 192.168.1.1 dev eth0 metric 100
sudo ip route add default via 10.0.0.1 dev wlan0 metric 600
# Confirm which path the kernel chooses
ip route get 8.8.8.8Two defaults with the same metric on the same interface fail with "RTNETLINK answers: File exists". Use different metrics, or the nexthop syntax for multipath.
Hidden problems behind a default
Because a default matches everything, it hides mistakes. If you mistype a static route for 10.2.0.0/16, traffic to 10.2.5.7 does not fail on your router. It silently follows the default to the ISP, which cannot route private addresses. The symptom is a timeout or an upstream ICMP error, not a local "no route". When something breaks, run ip route get <destination> or show ip route <destination> and read which entry matched.
Private address space leaking
A default route also sends traffic for unused or private ranges to the provider. Some networks add explicit discard routes for those ranges so the router drops them locally.
# Drop traffic for an unused private range instead of sending it upstream
sudo ip route add blackhole 10.99.0.0/16This route is more specific than the default, so it wins for 10.99.0.0/16 and the packets are discarded locally.
When a default route is the right choice
- Stub networks. A site with a single exit needs only one default. Any longer table adds nothing.
- Hosts. Nearly all hosts use only connected routes and one default.
- Edge of a dynamic domain. The border router injects a default so interior routers do not hold external routes.
It is a poor fit where there are several exits and the best exit depends on the destination. A multihomed site with two ISPs and a default to only one cannot use the other for destinations it reaches better. That case calls for a protocol such as BGP, or more specific routes alongside the default.
Exercise
A router has these routes: 10.0.0.0/8 via 192.168.1.2, 10.2.0.0/16 via 192.168.1.3, and 0.0.0.0/0 via 192.168.1.1. Which next hop is used for 10.2.5.7, for 10.9.9.9 and for 172.16.0.5, and why?
Show answer
10.2.5.7 goes to 192.168.1.3, because /16 is the longest matching prefix. 10.9.9.9 goes to 192.168.1.2, because only the /8 and the default match, and /8 is longer. 172.16.0.5 goes to 192.168.1.1, because only the default route matches.
Exercise
An edge router has a static default to the ISP and runs OSPF with "default-information originate" (no "always"). The ISP link fails. What happens to the default route in the OSPF domain, and why is this useful?
Show answer
The static default is removed because its next hop becomes unreachable. Without "always", OSPF stops advertising the default, so interior routers lose it and do not send traffic to a router with no exit. If "always" were set, the router would keep attracting traffic it cannot forward.