Articles

Static routes and default routes: telling a router where to forward

How a static route and a default route are written on Cisco IOS-XE, how the router chooses between routes, and when a manually configured route fails silently.

Reading: 4 minNetworking

Article cover: Static routes and default routes: telling a router where to forward

Static routing is manual: an administrator writes each destination prefix and the path the router must use, and the router keeps that entry until the configuration changes or the path disappears. A default route is the extreme case — one entry that matches every destination with no more specific route — written 0.0.0.0/0 in IPv4 and ::/0 in IPv6 and shown as the gateway of last resort. Static routes fit a small, stable network, a single exit to an upstream router, or a backup path; they stop fitting when the topology changes faster than anyone can keep them correct. The commands below are Cisco IOS-XE; the concepts are portable, the syntax is not.

The model: one manual entry, plus a catch-all

A route pairs a destination prefix with a way to reach it: a next-hop address, an exit interface, or both. The router’s first decision is longest prefix match — the most specific prefix covering the destination wins — and only routes for the same prefix are compared by administrative distance and metric. The default route is the least specific match, a prefix of length zero, used only when nothing else matches.

destination address
        ↓
longest prefix match in the routing table
        ↓
a more specific prefix matches? ── yes ──▶ forward to that route's next hop
        │ no
        ▼
default route (0.0.0.0/0 or ::/0)
        ↓
the gateway of last resort

Terms

  • Destination prefix and mask — the network to reach; the IPv4 ip route syntax takes a dotted mask, not a wildcard.
  • Next hop — the adjacent router interface the packet is handed to.
  • Exit interface / fully specified route — the local interface the packet leaves through; fully specified means the exit interface and the next hop together.
  • Administrative distance (AD) — a Cisco ranking, 0 to 255, of how trustworthy a route source is; lower wins. Connected 0, static 1.
  • Floating static route — a static route given a higher AD, so a dynamic route wins while it exists and the static takes over when it disappears.

How a static route is written, step by step

  1. Choose the destination prefix and the next hop. On a multi-access link such as Ethernet, give the next-hop address, or the exit interface and the next-hop address together — a fully specified route; naming only the exit interface makes the router resolve the link-layer address of every destination in the prefix separately.
  2. Write the route in global configuration mode:
ip route 192.0.2.0 255.255.255.0 203.0.113.1
ipv6 route 2001:db8:1::/48 2001:db8:ff::1
  1. For a default route, use the all-zero prefix:
ip route 0.0.0.0 0.0.0.0 203.0.113.1
ipv6 route ::/0 2001:db8:ff::1
  1. A next-hop-only route is recursive: the router looks the next hop up in the routing table to learn the exit interface, and installs the route only if that lookup succeeds — and it stays installed while anything still resolves that next hop, even when the intended path is gone.
  2. The route takes effect in the running configuration immediately; surviving a reload is a separate step, saving the running configuration.

Warning. A static route changes forwarding the moment it is entered; there is no automatic rollback. A wrong next hop, or a prefix more specific than the one you meant to override, can blackhole traffic, because longest prefix match honours the more specific entry. Removing a live route with no ip route drops that path at once.

One worked example

        +--------------+         192.0.2.0/24        +--------------+
        |   Branch R   |─────────────────────────────|    Core R    |──▶ upstream
        |  10.0.0.0/24 |  .1                       .2 |              |
        +--------------+                             +--------------+
              │ users

Branch R has its users directly connected and one link to Core R. It needs a default route and a specific route to a remote site:

ip route 0.0.0.0 0.0.0.0 192.0.2.2
ip route 198.51.100.0 255.255.255.0 192.0.2.2

Verification means reading the table, not trusting the configuration. show ip route displays static entries coded S, the default marked S*, each line carrying the prefix, the administrative distance and metric in brackets, and the next hop; the gateway of last resort is named above the table. show ip route static lists only statics — a configured route that is missing failed to install, usually because its next hop cannot be resolved. show ipv6 route static and show ipv6 static do the same for IPv6.

Limits and the common mistake

  • Static routes do not react to change. Nothing recalculates them when a failure happens elsewhere; IOS-XE removes a static route when its interface goes down and reinstalls it when the interface returns. The permanent keyword keeps the entry even then, hiding the failure.
  • A static route does not automatically win. Longest prefix match runs first, so a more specific route from any source beats a less specific static one; administrative distance breaks ties only for the same prefix. A static default of 0.0.0.0/0 never overrides a real prefix.
  • A floating static needs an AD above every competing source, not only the primary.
  • IPv6 adds a wrinkle. By default a recursive IPv6 static route will not resolve through the default route; Cisco documents ipv6 route static resolve default. IPv6 static routing also requires ipv6 unicast-routing and an IPv6-enabled interface.

Level and prerequisites. L2 — operational. It assumes the L1 concepts — the on-link or off-link decision and the gateway hand-off (the prefixes and default gateway sheet), hop-by-hop forwarding (the packet-journey sheet), and next-hop resolution (the Ethernet and ARP/ND sheets) — and builds on top.

Where to go next

References

  • RFC 1812 — Requirements for IP Version 4 Routers (F. Baker, Ed., June 1995): longest match and the static-versus-dynamic tie-breaker, Appendix E.1.
  • RFC 4632 — Classless Inter-Domain Routing (CIDR), BCP 122 (Fuller, Li, August 2006): prefix notation and 0.0.0.0/0 as the default route, §3.1.
  • RFC 791 — Internet Protocol (September 1981): gateways and forwarding between networks, §2.4.
  • Cisco — Basic IP Routing, IP Routing Configuration Guide, Cisco IOS XE: static routes, default routes, gateway of last resort, administrative distances, and route removal when the interface or next hop is lost.
  • Cisco — IPv6 Routing: Static Routing, IP Routing Configuration Guide, Cisco IOS XE 17.x: ipv6 route syntax, directly attached, recursive, fully specified and floating static routes, ::/0, ipv6 route static resolve default, prerequisites.
  • Cisco — IP Routing Protocol-Independent Commands: A through R, Cisco IOS IP Routing: Protocol-Independent Command Reference: ip route syntax, permanent and track.
  • Cisco — IP Routing Protocol-Independent Commands: S through T, Cisco IOS IP Routing: Protocol-Independent Command Reference: show ip route (including the static keyword) and show ip static route.
  • Cisco — Managing Configuration Files, System Management Configuration Guide, Cisco IOS XE 17.15.x (Catalyst 9200): running versus startup configuration and saving the running configuration.