Routing
Choosing a next hop. Tables, longest prefix match, and intra- vs inter-domain.
Level: intermediate
What is it?
Routing determines paths or next hops for packets between IP networks. Routers maintain a forwarding table derived from connected networks, static routes, and routing protocols, then use destination-prefix matching to select an outgoing interface and next hop.
Why does it matter?
Correct routing connects independent subnets and allows a network to adapt to topology changes. Incorrect or missing routes create black holes, loops, asymmetric paths, or excessive convergence time after failures.
Mental model
Separate route computation from packet forwarding. Control-plane protocols learn and select routes; the forwarding plane performs a fast lookup for each packet using the resulting table.
How it works
- Longest-prefix match chooses the most specific matching destination prefix.
- A default route is used when no more specific applicable route exists.
- Routing protocols exchange reachability information; they use different metrics, policies, and convergence models.
- Route preference and metrics are implementation- and protocol-specific, so route selection should be read from the actual routing table.
- TTL/hop-limit fields limit looping packets but do not repair a faulty routing configuration.
Steps
- A host compares a destination IP with connected prefixes.
- If the destination is remote, its routing table selects the best route or default gateway.
- The router forwards to the next hop or directly connected destination interface.
- Each subsequent router repeats the lookup based on the packet's destination prefix.
Real-world usage
- Reading `ip route` or router forwarding tables.
- Diagnosing asymmetric routing and unreachable subnets.
- Distinguishing routing protocol convergence from packet forwarding.
Common mistakes
- Assuming a router uses the DNS name in every packet lookup; ordinary forwarding uses IP destination fields.
- Assuming a longer route is always preferred; longest-prefix match concerns prefix specificity, not hop count.
- Changing routes without checking return paths, ACLs, NAT, or routing policy.
Interview questions
What is longest-prefix match?
Among routes matching a destination IP, the router selects the matching route with the greatest prefix length.
How do routing and forwarding differ?
Routing computes or selects reachability paths and next hops; forwarding applies the installed table to individual packets.