The default gateway
Is the destination on my network, or must the packet leave it?
A host compares network parts: a match means deliver directly; a mismatch means send the packet to the default gateway, a router.
Every packet a host sends starts with the same decision. The host knows three things: its address, its mask and its gateway. Address and mask together say which network it is on. A packet for one nine two, one six eight, ten, twenty: the network part is the same as the host’s own. That machine is a neighbour, so the packet goes straight to it. A packet for two oh three, zero, one one three, ten: the network part differs. The host cannot reach it directly, so it hands the packet to the gateway, a router, and lets the router work out the rest.
ARP
One broadcast question turns an IP address into a MAC address
ARP broadcasts “who has this IP?”; the owner replies with its MAC, and the asker caches the answer.
A frame needs a destination MAC address, but the PC only knows the IP address it wants. So it shouts to the whole local network: who has one nine two dot one six eight dot one dot one? Tell one nine two dot one six eight dot one dot ten. Every device hears the broadcast. Only the gateway, which owns that address, answers, directly to the PC: that address is at this MAC. The PC caches the answer and can now build frames for it.
ARP · Going deeper
Local or remote: when a host ARPs for the gateway
For a destination on its own subnet, a host ARPs for that host. For anything else, it ARPs for its default gateway.
Routing tables
Each router decides only the next hop
A router looks up the destination in its routing table and forwards to the next hop; no router knows the whole path.
A packet to a distant server crosses three routers, and each one makes its own small decision. R1 has no route for the server’s network, so it uses its default route: send it to R2. R2 has a route for that network, pointing at R3. R3 is directly connected to the server’s network and delivers it. None of them planned the whole journey. Each only answered: which neighbour next?
Routing tables · Going deeper
What a router does to every packet
Receive and check the frame, read the IP header, look up the destination, lower the TTL, rebuild the frame for the next link.
Longest prefix match
The most specific matching route wins
For 10.1.2.77, the /0, /8, /16 and /24 all match; the longest prefix, 10.1.2.0/24, is used.
When several routes match, the router picks the most specific. The default route matches everything, with zero bits. Ten slash eight matches the first eight bits. Ten dot one slash sixteen matches sixteen. Ten dot one dot two slash twenty-four matches twenty-four bits: the longest, so the packet goes to R4. Ten dot one dot three does not match at all, because the third octet differs.
Longest prefix match · Going deeper
Reading show ip route
Each route shows its source code, prefix, administrative distance and metric, next hop and exit interface. The gateway of last resort is the default.
Static and floating routes
A floating static route waits behind a better one
A floating static route has a worse administrative distance than the primary, so it is installed only when the primary is gone.
Static routes are typed in by hand. This branch reaches the internet over fibre with a default static route. Distance one: it goes straight into the table. A second default route points at a 4G backup, but with distance two hundred. It loses to the first and stays out of the table, floating. When the fibre interface goes down, the first route is removed and the backup drops into place automatically.
Static and floating routes · Going deeper
Default, network, host and floating static routes
A default route (0.0.0.0/0), a network route, a host route (/32) and a floating route are all static routes with different prefixes or distances.
Troubleshooting addresses
Most addressing faults are a mask or gateway that disagrees with the subnet
Check every host: address inside the subnet, the subnet’s mask, and a default gateway in the same subnet.
When one host cannot get out, compare its settings with the design. The network is one nine two dot one six eight dot one dot zero, slash twenty-five. PC one is right. PC two has an address in the upper half, outside this subnet, so its gateway is unreachable. PC three has a slash twenty-four mask. It thinks addresses up to two fifty-five are local and tries to reach them directly. PC four has a one six nine dot two five four address: it never heard from a DHCP server and gave itself one.
Addresses at each layer
The IP address travels end to end; the MAC address changes every hop
A router strips the old frame and builds a new one, so MAC addresses change at every hop while the IP addresses stay the same.
Watch what changes as a packet crosses one router. On the first link, the frame is addressed from the PC’s MAC address to the router’s MAC address. Inside it, the IP packet says: from one nine two dot one six eight dot one dot ten, to the server, two oh three dot zero dot one one three dot ten. On the next link, the router has built a brand new frame, from its own other interface to the server’s MAC address. The IP addresses inside are unchanged, and so are the ports. MAC addresses only mean something on one link. IP addresses mean something everywhere.
Addresses at each layer · Going deeper
Port, IP address, MAC address: what each one names
A port names a program, an IP address a host, a MAC address a device on one link. Five values together, the 5-tuple, name one connection.
Devices and layers
Each device opens the packet only as far as its job needs
A switch reads up to layer 2 and a router up to layer 3; only the two end hosts unwrap everything.
Now follow the same request through four devices. Your PC wraps it all the way down to bits. The switch reads only the frame, decides which port to send it out of, and sends it on. The router removes the frame, reads the IP header, chooses the next hop, and wraps the packet in a fresh frame. Only the server unwraps all the way up to the request. The less a device has to read, the faster and cheaper it can be.