LearnNetwork
Routing fundamentals

Routing fundamentals — static, default, longest match

12 min

A router is a state machine with one job: receive a packet on one interface, look at its destination IP, decide which interface to send it out (and to whose MAC). The decision is driven by the routing table (RIB) and the rules for picking entries from it.

The routing table

Every router has a routing table. Each entry is a destination prefix → next-hop interface (and optionally next-hop IP). Source-of-entry codes:

| Code | Source | |---|---| | C | Directly Connected (the prefix on a configured interface) | | L | Local (the router's own IP on that interface) | | S | Static (manually configured) | | O | OSPF | | R | RIP | | B | BGP | | D | EIGRP | | i | IS-IS |

Cisco IOSshow ip route
[object Object],[object Object],[object Object]

The two numbers in brackets [110/30] are administrative distance and metric — see below.

The decision: longest-prefix match

When a packet arrives, the router looks for the most specific matching prefix. /32 is more specific than /24 which is more specific than /0. If multiple entries match, the longest prefix wins.

Example: packet to 10.0.0.5. Table contains:

  • 0.0.0.0/0 (default)
  • 10.0.0.0/24
  • 10.0.0.0/30

All three "match." Longest prefix: /30 wins. Forward out the interface for that entry.

Administrative distance (AD)

When multiple routing protocols learn the same prefix, the router prefers the one with the lowest administrative distance — a Cisco-defined trust score:

| Source | AD | |---|---| | Connected | 0 | | Static | 1 | | EIGRP summary | 5 | | eBGP | 20 | | EIGRP (internal) | 90 | | OSPF | 110 | | IS-IS | 115 | | RIP | 120 | | EIGRP (external) | 170 | | iBGP | 200 | | Unknown / disabled | 255 |

A static route to 192.0.2.0/24 has AD 1, so it beats any dynamic-protocol route to the same prefix. Useful for emergency overrides; risky for production because it ignores topology changes.

Static routes — the worked syntax

ip route <destination> <mask> <next-hop>
ip route <destination> <mask> <exit-interface>
ip route <destination> <mask> <next-hop> <distance>   ! optional AD
Cisco IOSA few static-route patterns
[object Object],[object Object],[object Object]

Metric

Within a single routing protocol, metric breaks ties between equal-AD routes. Each protocol has its own metric definition: OSPF uses cost (bandwidth-based), BGP uses a stack of path attributes, EIGRP uses a composite of bandwidth and delay.

The metric is only compared within a single protocol. AD is compared across protocols.

The full forwarding decision

  1. Look up destination IP in the routing table.
  2. Find the longest-prefix match.
  3. If multiple entries match at the same prefix length, pick the lowest AD.
  4. If multiple entries from the same source: lowest metric (or load-balance across them, if ECMP).
  5. Forward out the selected interface to the next-hop's MAC (resolved via ARP / NDP).

Default route

0.0.0.0/0 matches everything (lowest possible specificity). It's the "if nothing else matches, send it this way" — typical at the edge of a network pointing at the upstream ISP. Inside a single AS, only the edge routers usually have a default; internal routers know more-specific routes via OSPF or IS-IS.

What to remember

  • Longest-prefix match wins, full stop.
  • Within the same prefix, lowest AD wins across protocols, then lowest metric within the chosen protocol.
  • 0.0.0.0/0 is the default — useful as last resort.
  • A static route with high AD is a "floating" backup that activates only when the preferred dynamic route disappears.