Notes
Our lab
Here is our lab. A network namespace gives a set of processes its own interfaces and routing table, the same isolation containers use. We created three: host A on ten dot zero dot one, host B on ten dot zero dot two, and a router with a leg in each. Virtual ethernet pairs, veth, act as cables between them. Everything that follows is real output from this lab.
ip netns add a; ... r; ... b ip link add va type veth peer name ra A 10.0.1.10/24 R 10.0.1.1/24 + 10.0.2.1/24 B 10.0.2.20/24 a namespace = its own interfaces and routes
Routing table
Every machine has a routing table. Host A has two routes. Ten dot zero dot one slash twenty four is directly connected, so those addresses are delivered on the local link. The default route says everything else goes via ten dot zero dot one dot one, the gateway. When several routes match, the most specific, the longest prefix, wins, and default, slash zero, is the least specific. ip route get shows the decision for any address.
default via 10.0.1.1 dev va 10.0.1.0/24 dev va scope link src 10.0.1.10 rule: the most specific matching route wins 10.0.1.x → deliver directly anything else → 10.0.1.1 $ ip route get <ip> asks
Break 1: no route
First break. Before we added the default route, host A pinged host B and got Network is unreachable, instantly. The packet never left the machine: no route matched ten dot zero dot two, so the kernel refused. This exact message in a container or VM usually means a missing default route or a missing interface. We added default via ten dot zero dot one dot one.
$ ping 10.0.2.20 ping: connect: Network is unreachable the kernel had no route at all, so it failed instantly, on the host fix: ip route add default via 10.0.1.1
Break 2: no forwarding
Second break. With routes on both hosts, ping still lost one hundred percent of packets. The router namespace had ip forward set to zero, the Linux default: a normal machine does not pass packets between interfaces. After setting it to one, three of three packets got through, in under a tenth of a millisecond. Docker and Kubernetes nodes turn this on, and a node where it was switched off is a classic broken-pod mystery.
router: net.ipv4.ip_forward
= 0
$ ping -c2 10.0.2.20
2 transmitted, 0 received,
100% packet loss
$ sysctl -w
net.ipv4.ip_forward=1
3 transmitted, 3 received,
0% packet loss, 0.038 ms ARP
The routing table names the next hop by IP address, but Ethernet delivers frames by MAC address. ARP bridges the gap. We cleared host A's cache and captured it: a broadcast asking who has ten dot zero dot one dot one, tell ten dot zero dot one dot ten, and the router replied with its MAC address. Host A caches the answer in its neighbour table, shown by ip neigh as reachable. Note: the MAC of the final host never matters, only the next hop's.
ARP, Request who-has 10.0.1.1 tell 10.0.1.10 ARP, Reply 10.0.1.1 is-at fa:b2:79:39:8d:ad $ ip neigh 10.0.1.1 lladdr fa:b2:79:39:8d:ad REACHABLE
TTL and traceroute
Every IP packet carries a time to live, and every router lowers it by one, so looping packets eventually die. Replies from host B had a TTL of sixty four when pinged from the router, and sixty three from host A, one hop further. traceroute uses this: it sends packets with TTL one, two, three, and each router that drops one reports back. Our path: hop one, the router, hop two, host B. On the internet you see a dozen hops, and where the replies stop.
ping from router: ttl=64 ping from host A: ttl=63 (one router on the way) $ traceroute -n 10.0.2.20 1 10.0.1.1 0.019 ms 2 10.0.2.20 0.006 ms TTL 0 → router drops it and sends "time exceeded"
In the cloud
In the cloud you rarely run routers, but the rules are identical. Each subnet has a route table: the VPC range is local, and zero slash zero goes to an internet gateway or a NAT gateway. Peering, VPNs and transit gateways just add more specific routes. The cloud fabric answers ARP for you. And Kubernetes networking, in part ten, installs routes so every node knows how to reach every pod range.
- each subnet has a route table 10.0.0.0/16 → local 0.0.0.0/0 → igw or nat
- peering, VPN, transit gateway = more specific routes
- no ARP to debug; the cloud fabric answers it
- Kubernetes: routes per node
Common mistakes
Mistakes. A container or VM with no default route. ip forward off on a machine meant to route. Asymmetric routing, where the reply returns by a different path and a firewall drops it. A route you did not expect winning because it is more specific. And the most common one: adding a route one way and forgetting the return route, so requests arrive and replies never do.
- missing default route in a container or VM
- ip_forward off on a router or Kubernetes node
- asymmetric paths: reply takes another route
- a broad route hiding a specific one you expected
- forgetting the return route
Say it like this
In the interview: the host looks up the destination in its routing table; nothing more specific matches, so it uses the default gateway. ARP resolves the gateway's MAC, the frame is sent there, and the router lowers the TTL and repeats the same lookup. To debug, I use ip route get, ip neigh and traceroute, and check forwarding is enabled and that a return route exists.
- "The host looks up the destination: no specific route, so the default gateway. ARP gets
- the gateway's MAC, the frame goes
- there, the router lowers TTL and repeats the lookup. I check ip
- route get, ip neigh, forwarding
- and the return route."