The IP Layer
TTL as a hop counter, how traceroute works, and MTU.
IP is the envelope. It reaches a machine and guarantees nothing else.
The IP header
tcpdump -v prints it before the TCP line:
cap "-i lo -n -v -c 1 tcp port 9000" \
"echo hi | nc -w 1 127.0.0.1 9000" | head -1| Field | Here | Means |
|---|---|---|
ttl |
64 |
hops remaining |
id |
a number | identifies fragments of one packet |
flags |
[DF] |
do not fragment |
proto |
TCP (6) |
what is inside |
length |
60 |
the whole packet, headers included |
proto
One number says what the payload is. TCP is 6:
cap "-i lo -n -v -c 1 udp port 9500" \
"echo hi | nc -u -w 1 127.0.0.1 9500" | head -1UDP is 17, ICMP is 1. The same envelope carries all three, and the kernel reads this field to decide where to hand it.
cap "-i eth0 -n -v -c 1 icmp" "ping -c 1 -W 2 1.1.1.1" | head -1TTL
Time to live, measured in hops. Every router decrements it; a packet reaching zero is dropped.
ping -c 1 -W 2 1.1.1.1 | sed -n 2p | grep -oE 'ttl=[0-9]+'It left with 64 and arrived with 63. The gateway, one hop closer, returns the full 64:
ping -c 1 -W 2 172.17.0.1 | sed -n 2p | grep -oE 'ttl=[0-9]+'Counting back from 64 is how you estimate the distance to a host.
Watching it expire
Send a packet that can only travel one hop:
ping -c 1 -t 1 -W 2 1.1.1.1 | sed -n 2p172.17.0.1 is the first router, reporting the drop. Allow two hops:
ping -c 1 -t 2 -W 2 1.1.1.1 | sed -n 2pThe router did not have to tell you. ICMP “time exceeded” is a courtesy, and the next section depends on routers sending it.
How traceroute works
That loop, with the TTL incrementing. Each router that drops a packet names itself:
traceroute -m 3 -w 1 -q 1 1.1.1.1MTU
The largest packet a link carries. Ethernet is 1500, which is where chapter 4’s MSS of 1460 comes from: 1500 minus 20 of IP and 20 of TCP.
ip link show eth0 | grep -oE 'mtu [0-9]+'Docker’s bridge is virtual, so it reports 65535 and nothing fragments here. On a real link it is 1500.
[DF] says “do not fragment, send an error instead”.
A router that cannot forward it replies with the size it can take, and the sender retries smaller. That is path MTU discovery.
IPv6, briefly
A longer address, a simpler header. What changes:
| IPv4 | IPv6 | |
|---|---|---|
| Address | 172.17.0.4 |
2001:db8::1 |
| Loopback | 127.0.0.1 |
::1 |
| In a URL | http://1.2.3.4:80 |
http://[2001:db8::1]:80 |
| Fragmentation | routers may | senders only |
| NAT | usual | unnecessary |
::1 is loopback, and it answers like any other address:
ping6 -c 1 -W 2 ::1 | sed -n 2pPorts, TCP, UDP and chapters 3 to 5 are identical. The brackets are what you will hit.