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)
- Each protocol picks its own best path with its own metric: OSPF cost, EIGRP composite metric, RIP hop count, the BGP best path algorithm.
- Each protocol offers that route to the RIB.
- 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.
- 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
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| Destination | Entries that match | Entry used | Why |
|---|---|---|---|
| 10.1.1.5 | /24, /16, /0 | RIP /24 | longest match, AD is never compared |
| 10.1.2.5 | /16, /0 | OSPF /16 | longest match |
| 192.0.2.10 | /0 | static default | only match |
If RIP and OSPF both advertised exactly 10.1.1.0/24, only the OSPF copy (AD 110) would be installed.
They will ask next
Can you compare an OSPF cost with an EIGRP metric?
No. A metric only means something inside its own protocol. Between protocols the router uses administrative distance, and only when the prefixes are identical.
What happens to the route that loses on AD?
It stays in its protocol's own table (OSPF database, EIGRP topology table, BGP table, static config) but not in the RIB. When the winner is removed, the next best source is installed. Floating static routes depend on exactly this behaviour.
Where does ECMP fit in this order?
After metric. If one protocol has several paths with the same best metric to the same prefix, all of them go into the RIB up to the
maximum-pathslimit, and CEF shares traffic across them per flow.
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.