Octet

Walk me through how a router decides where to send a packet.

Show the answer

Say this first

There are two separate jobs. To build the table, the router keeps one source per exact prefix: the lowest administrative distance wins, and inside one protocol the lowest metric wins (equal metrics become ECMP). To forward a packet, it uses the longest prefix in the table that matches the destination. Prefix length comes first: a /24 from RIP beats a /16 from OSPF, because AD only compares routes to the same prefix.

Go deeper

Building the routing table (control plane)

  1. Each protocol picks its own best path with its own metric: OSPF cost, EIGRP composite metric, RIP hop count, the BGP best path algorithm.
  2. Each protocol offers that route to the RIB.
  3. If two sources offer the same prefix and the same length, the lower administrative distance wins. The loser stays in its own protocol table and is installed if the winner goes away.
  4. Equal-metric paths from one protocol are installed together, up to maximum-paths.

Forwarding a packet (data plane)

CEF looks up the destination in the FIB, which is built from the RIB, and uses the most specific matching entry. If nothing matches and there is no default route, the packet is dropped and the router sends ICMP Destination Unreachable to the source.

Worked example

Output
O     10.1.0.0/16 [110/20] via 10.0.12.2
R     10.1.1.0/24 [120/2] via 10.0.13.2
S*    0.0.0.0/0 [1/0] via 203.0.113.1
DestinationEntries that matchEntry usedWhy
10.1.1.5/24, /16, /0RIP /24longest match, AD is never compared
10.1.2.5/16, /0OSPF /16longest match
192.0.2.10/0static defaultonly match

If RIP and OSPF both advertised exactly 10.1.1.0/24, only the OSPF copy (AD 110) would be installed.

Traps

  • Saying the router checks administrative distance first when forwarding. AD only decides which source installs a prefix; the lookup itself is longest match.
  • Blending the two jobs together. Interviewers listen for the split between building the table and using it.
How did you do?Book 3.3 Internet (IP)Book 3.4 Routing