Lesson 1 of 3
How routers decide
1 min
Every router holds a routing table: a list of networks and where to send packets for each. On Linux, view it with ip route:
default via 203.0.113.1 dev eth0
10.0.0.0/16 via 10.0.0.1 dev eth1
10.0.5.0/24 via 10.0.0.9 dev eth1Longest prefix wins
For a packet to 10.0.5.20, both 10.0.0.0/16 and 10.0.5.0/24 match. The router picks the most specific one, /24. The default route (0.0.0.0/0) matches everything, so it's used only when nothing else does.
Where routes come from
- Connected: networks directly on the router's interfaces.
- Static: typed in by an administrator. Simple, but they don't react to failures.
- Dynamic: learned from other routers with protocols like OSPF (inside a company) or BGP (between companies).
When paths are equal
If two routes have the same prefix, the router uses the one with the best administrative distance and metric. Some routers spread traffic across equal paths (ECMP).
Most "can't reach X" problems are a missing return route. The packet arrives, but the reply has no path home.