Make the router choose between four routes
Task
Install several overlapping routes to the same destination and work out, before testing, which one the router will use. Longest prefix match, administrative distance and metric are the three-step selection rule, and this lab makes you apply all three.
Steps
- On the router, note the existing connected routes:
ip route show. Connected routes are why the lab works at all, and they win over everything because nothing is more specific or more trusted than an interface you own. - Add three overlapping static routes toward Host B's address, each with a different prefix length:
sudo ip route add 192.168.0.0/16 via 192.168.10.10,sudo ip route add 192.168.20.0/24 dev eth1, andsudo ip route add 192.168.20.10/32 via 192.168.10.10. - Predict which one applies to a packet for 192.168.20.10 before you test. Longest prefix wins, so the /32 does — even though it points somewhere absurd.
- Test with
ip route get 192.168.20.10, which asks the router what it would do without sending anything. Then remove the /32 and test again. Then remove the /24 and test again. - Now add two routes with the same prefix but different metrics:
sudo ip route add 10.9.9.0/24 via 192.168.10.10 metric 100and the same via 192.168.20.10 with metric 50. Predict and test which is chosen.
Verify
ip route get 192.168.20.10
ip route show | sort
sudo ip route del 192.168.20.10/32; ip route get 192.168.20.10
ip route get 10.9.9.1
Each ip route get must name the next hop your prediction chose. When the /32 is present it must be used; when it is deleted the /24 must take over; and for 10.9.9.1 the metric-50 route must win over the metric-100 one.
Notes
The order is the thing to carry into the exam: longest prefix first, then administrative distance, then metric. Prefix length is decided before anything else, which is why a bad /32 static route beats a perfectly good dynamic route — and why "the route is there but traffic is not taking it" is nearly always a more specific route somewhere else in the table.
Administrative distance is the tie-breaker between protocols, not between routes of one protocol. The numbers worth knowing: connected 0, static 1, eBGP 20, OSPF 110, RIP 120. Lower is more trusted.
Metric only ever compares routes from the same protocol, which is the distinction most often got backwards.