3.2 Determine how a router decides where to forward a packet
CCNA 200-301 v1.1 · 3.0 IP Connectivity
For every packet the router asks three questions in a fixed order. Which routes match the destination at all, and which of them is the longest prefix? Only if two sources offer the same prefix length does administrative distance decide which one is installed, and only between routes from the same protocol does the metric decide. Get the order right and most routing questions answer themselves.
What you must know
- Find the matching routes for an address and pick the longest prefix.
- Explain why AD and metric are not compared against the prefix length.
- Use AD to decide which source's route is installed for the same prefix.
- Use the metric to choose between routes of one protocol, and recognise equal-cost load sharing.
- Say what happens to a packet that matches no route.
Longest prefix match
A route matches when the destination's first bits equal the prefix for the length of the mask. Several routes often match; the router always uses the most specific one, the longest prefix.
| Route in R1's table | Matches 10.1.1.70? | Why |
|---|---|---|
| 0.0.0.0/0 via R3 | Yes | The default matches everything (0 bits). |
| 10.0.0.0/8 via R3 | Yes | First 8 bits are 10. |
| 10.1.0.0/16 via R3 | Yes | First 16 bits are 10.1. |
| 10.1.1.64/26 via R2 | Yes, and it wins | 10.1.1.64 to 10.1.1.127 includes .70, and /26 is the longest. |
| 10.1.1.128/25 via R2 | No | .70 is outside 10.1.1.128 to 10.1.1.255. |
So a packet to 10.1.1.70 goes to R2 (1). A packet to 10.9.9.9 only matches the /8 and the default, so it goes to R3 (2). If R1 had no default route, a packet to 172.16.5.5 would match nothing and be dropped (3).
Administrative distance
AD is used before a route enters the table, not per packet. If OSPF (110) and a static route (1) both offer 10.1.1.64/26, only the static route is installed. If OSPF offers 10.1.1.64/26 and a static route offers 10.1.0.0/16, both are installed, because they are different prefixes, and the /26 still wins for 10.1.1.70.
Routing protocol metric
Within one protocol, the route with the lowest metric is installed: the lowest OSPF cost, the lowest EIGRP composite metric, the fewest RIP hops. If several routes tie, the router installs them all (four by default for OSPF and EIGRP) and shares traffic between them, per flow.
- Longest prefix match picks the route for each packet.
- Administrative distance chooses between sources for the same prefix and length.
- Metric chooses between routes of the same protocol.
Commands
show ip route 10.1.1.70 | The route an address uses: the longest match, with its source and next hop. |
show ip route longer-prefixes 10.1.0.0 255.255.0.0 | Every more specific route inside a range. |
show ip cef 10.1.1.70 | The forwarding entry the hardware actually uses. |
traceroute 10.1.1.70 | The hops a packet really takes. |
Exam traps
- A /26 learned by RIP (AD 120) beats a /24 static route (AD 1) for an address inside the /26. Prefix length comes first.
- AD never compares routes with different prefix lengths.
- Metrics of different protocols cannot be compared: OSPF cost 2 is not "better" than EIGRP 130816.
- Equal-cost routes appear as several
vialines under one prefix. - No match and no default route means the packet is dropped, and the sender gets an ICMP unreachable.
Check yourself
- A router has 172.16.0.0/16 via A, 172.16.4.0/22 via B and 172.16.5.0/24 via C. Where does it send 172.16.5.9? And 172.16.6.1?
- 172.16.5.9 to C (the /24 matches). 172.16.6.1 to B: the /22 covers 172.16.4.0 to 172.16.7.255, and the /24 does not match.
- A static route and OSPF both offer 10.8.0.0/16. Which appears in the table?
- The static route, AD 1 against 110.
- Two OSPF routes to the same prefix have costs 20 and 20. What does the router do?
- Installs both and shares traffic between them (equal-cost multipath).
- Why does a floating static route stay out of the table?
- Its AD is higher than the dynamic route's for the same prefix, so it is only installed when the dynamic route is lost.
Labs
Try it live: Static and floating static routes