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

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 tableMatches 10.1.1.70?Why
0.0.0.0/0 via R3YesThe default matches everything (0 bits).
10.0.0.0/8 via R3YesFirst 8 bits are 10.
10.1.0.0/16 via R3YesFirst 16 bits are 10.1.
10.1.1.64/26 via R2Yes, and it wins10.1.1.64 to 10.1.1.127 includes .70, and /26 is the longest.
10.1.1.128/25 via R2No.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.

  1. Longest prefix match picks the route for each packet.
  2. Administrative distance chooses between sources for the same prefix and length.
  3. Metric chooses between routes of the same protocol.

Commands

show ip route 10.1.1.70The 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.0Every more specific route inside a range.
show ip cef 10.1.1.70The forwarding entry the hardware actually uses.
traceroute 10.1.1.70The hops a packet really takes.

Exam traps

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

More topics in 3.0 IP Connectivity