The default gateway

Is the destination on my network, or must the packet leave it?

This hostaddress 192.168.10.77mask 255.255.255.0gateway 192.168.10.1My network is everything thatstarts 192.168.10to192.168.10.20✓same networkstraight there192.168.10.20to203.0.113.10✗another networkthe gatewayonwardsBefore sending anything, a host asks one question: is the destination on my own network?It compares the network part of its own address with the same bits of the destination. If they match, thedestination is a neighbour and the packet goes straight to it. If they differ, the packet goes to the default gateway,the router that leads out, and the router repeats the question with its own table. A host with the wrong mask orgateway gets this first decision wrong, and nothing after it can work.

A host compares network parts: a match means deliver directly; a mismatch means send the packet to the default gateway, a router.

ARP

One broadcast question turns an IP address into a MAC address

One LAN: 192.168.1.0/24PC192.168.1.10Gateway192.168.1.1 · 00:00:0c:9f:f0:0aPrinter192.168.1.40Request, to everyone (FF:FF:FF:FF:FF:FF):Who has 192.168.1.1? Tell 192.168.1.10Reply, to the PC only:192.168.1.1 is at 00:00:0c:9f:f0:0ahears it, ignores itARP turns an IP address on the local link into a MAC address, with one broadcast question and one direct answer.The PC knows the IP address it must reach next but a frame needs a MAC address. Every host on the link hears thequestion; only the owner answers. The PC keeps the answer in its ARP cache for a few minutes (Windows: about 30 to45 seconds unused; Cisco IOS: 4 hours) so it does not ask for every packet. IPv6 replaces ARP with neighbour discovery.

ARP broadcasts “who has this IP?”; the owner replies with its MAC, and the asker caches the answer.

ARP · Going deeper

Local or remote: when a host ARPs for the gateway

Before sending, the PC compares the destination with its own network, using its subnet maskTo 192.168.1.40 (the printer)same network 192.168.1.0/24ARP for 192.168.1.40 itselfframe goes straight to the printerTo 203.0.113.10 (a web server)a different networkARP for 192.168.1.1, the gatewayframe goes to the router; the IP still says 203.0.113.10C:\> arp -a  192.168.1.1     00-00-0c-9f-f0-0a   dynamic  192.168.1.40    3c-22-fb-10-9e-41   dynamicA host never ARPs for a remote server. A wrong maskor a wrong gateway breaks exactly this decision, andlocal printing works while the internet does not.For a host on its own network the PC asks for that host’s MAC. For anything else, it asks for the gateway’s.This one decision is behind most “I can reach the printer but not the internet” tickets. A gratuitous ARP, an answernobody asked for, announces an address after a failover; ARP spoofing abuses the same trust, and dynamic ARPinspection (lesson 14) stops it.

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

PCServer198.51.100.7R1192.168.1.0/24direct0.0.0.0/0via R2R210.0.0.0/8via R4198.51.100.0/24via R30.0.0.0/0via ISPR3198.51.100.0/24direct0.0.0.0/0via R2Every router asks the same question of the destination, 198.51.100.7, and answers only “which neighbour next?”Each router decides only the next hop. No router knows, or needs to know, the whole path.R1 has no specific route, so it uses its default. R2 has a route for the server’s network and sends the packet to R3. R3 isdirectly connected and delivers it. At every hop the router lowers the TTL by one and builds a new frame for the next link.The reply is routed separately and may take a different path back.

A router looks up the destination in its routing table and forwards to the next hop; no router knows the whole path.

Routing tables · Going deeper

What a router does to every packet

1Frame inFCS checked2IP header readframe removed3Lookuplongest match4TTL − 1dropped at 05Checksumrecomputed6Next-hop MACfrom the ARP cache7New framequeued and sentNo route, no default: dropped,and ICMP unreachable sent backFor every packet a router strips the frame, looks up the destination, lowers the TTL and builds a new frame.Modern routers do this in hardware for millions of packets a second. The lookup is the only real decision; everything elseis bookkeeping. TTL reaching zero sends ICMP “time exceeded” back to the source, which is what traceroute listens for.If the next hop’s MAC is not cached, the router ARPs for it first, so the first packet to a new neighbour is a little slower.

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

Destination 10.1.2.77bits of the destination this route matches (of 32)081624320.0.0.0/0via ISPmatches10.0.0.0/8via R2matches10.1.0.0/16via R3matches10.1.2.0/24via R4matches, and longest: used10.1.3.0/24via R5does not match: .3 ≠ .2The most specific matching route wins, whatever order the routes are listed in.Four of the five routes contain 10.1.2.77; the /24 matches 24 bits, more than any other, so the packet goes to R4. The defaultroute, 0.0.0.0/0, matches every address with zero bits, so it is used only when nothing else matches. Prefix length iscompared first; administrative distance and metric only choose between routes to the same prefix.

For 10.1.2.77, the /0, /8, /16 and /24 all match; the longest prefix, 10.1.2.0/24, is used.

Longest prefix match · Going deeper

Reading show ip route

R2# show ip routeGateway of last resort is 203.0.113.1 to network 0.0.0.0S*    0.0.0.0/0 [1/0] via 203.0.113.1O     10.1.0.0/16 [110/20] via 10.0.23.3, 00:14:07, Gi0/0/1C     10.0.23.0/30 is directly connected, Gi0/0/1L     10.0.23.2/32 is directly connected, Gi0/0/1S     198.51.100.0/24 [1/0] via 10.0.23.3Codehow it was learned: C connected, L local, Sstatic, O OSPF, D EIGRP, B BGP; * default[110/20]administrative distance / metric: trust in thesource, then its costviathe next-hop address, then how long ago, thenthe exit interfaceL /32the router’s own address on that linkRead a route left to right: how it was learned, what it covers, how trusted and how costly, and where it goes next.The exam asks you to pick the next hop for a given destination from output like this: find every route that contains it,take the longest prefix, and read its via. show ipv6 route reads the same way. A route that is configured but missingfrom the table usually has a next hop that cannot be reached.

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

Branch routerLAN 10.20.0.0/16Fibre to ISP Aip route 0.0.0.0 0.0.0.0 203.0.113.1distance 1: in the table, carrying traffic4G backup to ISP Bip route 0.0.0.0 0.0.0.0 198.51.100.1 200distance 200: waits behind the fibre routefibre fails →backup installedA floating static route waits behind a better route and takes over only when that route disappears.Routes to the same prefix compete on administrative distance; the lower one goes in the table. Giving the backup a distanceof 200, worse than the primary static (1) or any routing protocol, keeps it out until the primary’s interface goes down. AddIP SLA tracking if the link can stay up while the path beyond it is dead, or the router will never notice.

A floating static route has a worse administrative distance than the primary, so it is installed only when the primary is gone.

Static and floating routes · Going deeper

Default, network, host and floating static routes

KindExample (IOS)UseDefaultip route 0.0.0.0 0.0.0.0 203.0.113.1everything not otherwise known: towards the internetNetworkip route 10.30.0.0 255.255.0.0 10.0.12.2one remote network, by next hopHostip route 10.30.5.9 255.255.255.255 10.0.12.6one address (/32), e.g. a monitoring server via a special pathFloatingip route 0.0.0.0 0.0.0.0 198.51.100.1 200a backup with a worse distanceExit interfaceip route 10.40.0.0 255.255.0.0 gi0/0/1point-to-point links only; on Ethernet it ARPs for every addressIPv6 defaultipv6 route ::/0 2001:db8:0:12::2the same idea; link-local next hops need the interface tooStatic routes are simple, predictable and silent, and they never notice when the path beyond the next hop breaks.They suit stub sites with one way out, default routes to an ISP and backups. In a network of more than a few routers, arouting protocol (lesson 12) adapts to failures that static routes cannot see.

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

The network: 192.168.1.0/25 · gateway 192.168.1.1 · hosts .1 to .126HostAddressMaskGatewayVerdictPC1192.168.1.20255.255.255.128 /25192.168.1.1✓correctPC2192.168.1.140255.255.255.128 /25192.168.1.1✗gateway is on another subnet (.0 – .127)PC3192.168.1.30255.255.255.0 /24192.168.1.1✗mask too wide: thinks .130 is localPC4169.254.17.9255.255.0.0 /16—✗self-assigned: DHCP never answeredMost addressing faults are a mask or a gateway that disagrees with the subnet the host is really on.Check three things against the design: is the address inside the subnet, is the mask the subnet’s mask, and is the gatewayinside the same subnet. PC3 can reach .1 to .126 but sends .130 to ARP instead of to the gateway. Duplicate addresses showas intermittent loss for two hosts; Windows reports a conflict, and arp -a shows one IP flipping between two MACs.

Check every host: address inside the subnet, the subnet’s mask, and a default gateway in the same subnet.

Addresses at each layer

The IP address travels end to end; the MAC address changes every hop

PC192.168.1.10RouterServer203.0.113.10EthernetMAC A → MAC R1IP192.168.1.10 → 203.0.113.10TCP51514 → 443EthernetMAC R2 → MAC SIP192.168.1.10 → 203.0.113.10TCP51514 → 443builds a new frameThe IP addresses stay the same end to end. The MAC addresses are replaced at every router.A MAC address only means something on one link, so each router strips the frame, reads the IP destination, and buildsa new frame addressed to the next device. The ports name the programs at each end: 443 is the web server, 51514 atemporary port the PC picked. (NAT, in lesson 10, is the exception that does rewrite IP addresses.)

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.

Addresses at each layer · Going deeper

Port, IP address, MAC address: what each one names

Portwhich program443, 53, 2216 bits · layer 4set by the applicationIP addresswhich host, anywhere203.0.113.1032 or 128 bits · layer 3set by you or by DHCPMAC addresswhich device on this link00:1A:2B:3C:4D:5E48 bits · layer 2burned in by the makerA connection is named by five things: protocol, source IP, source port, destination IP, destination port.Three addresses, three questions: which program, which host, and which device on this wire.ARP (lesson 6) finds the MAC address that goes with an IP address on the local link; DNS (lesson 10) finds the IPaddress that goes with a name. The five-part “5-tuple” is how firewalls, NAT and load balancers tell connections apart.

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

Your PC5-74321Switch5-74321Router5-74321Server5-74321down all fiveup to 2, down againup to 3, then up all fiveEach device unwraps a packet only as far as its job needs, then wraps it again and sends it on.A switch reads the frame and stops. A router removes the frame, reads the IP header, and builds a new frame for the nextlink. Only the two end hosts open everything. This is why a switch is fast and simple, and why a firewall that readslayer 7 costs far more processing per packet than one that reads layer 4.

A switch reads up to layer 2 and a router up to layer 3; only the two end hosts unwrap everything.

Lesson complete

You finished “Routing”

Nicely done.

Open in a new tab