SkillPilotAI

ICMP, TTL and MTU

ICMP is the network's error and control messenger, TTL stops packets from looping forever, and MTU is the biggest packet a link can carry. Ping, traceroute and downloads that hang on a VPN all depend on these three, so they are the base of daily troubleshooting.

37.1 Why does it matter?

  • When a packet cannot be delivered, a router sends an ICMP error back (e.g. Destination Host Unreachable) so the sender knows what went wrong.
  • ping and traceroute are built entirely on ICMP and TTL.
  • A download that hangs on a VPN is very often an MTU problem.

37.2 ICMP and its message types

  • ICMP = Internet Control Message Protocol. It carries no user data; it reports errors and network health.
  • ping is ICMP: the PC sends an echo request, the server sends an echo reply.
  • Example: PC pings 192.168.57.140; router 2 has no such host on its network, so it replies Destination Host Unreachable.
TypeNameWhen you see it
8 / 0Echo request / echo replyping
3Destination unreachableCodes inside: host unreachable, port unreachable, fragmentation needed (code 4)
11Time exceededTTL reached 0 at a router
5RedirectRouter hints the host about a better gateway

37.3 TTL: one less at every router

  • Every IP packet has a TTL (Time To Live) field; Linux starts at 64 (Windows 128).
  • Each router decrements it by 1: 64 -> 63 after router 1 -> 62 after router 2, so the server gets TTL 62.
  • Purpose: protection from routing loops. A packet stuck in a loop is dropped when TTL hits 0.
  • The router that drops it sends ICMP Time Exceeded back, carrying the router's own IP.
How traceroute uses TTL
  1. 1.Probe 1 with TTL 1: router 1 drops it, replies Time Exceeded -> hop 1 = 192.168.57.1

  2. 2.Probe 2 with TTL 2: router 2 drops it, replies Time Exceeded -> hop 2 = 192.168.57.66

  3. 3.Probe 3 with TTL 3 reaches the server on a high UDP port

  4. 4.Server replies ICMP Port Unreachable -> destination reached

  5. 5.Path is built hop by hop

37.4 Practical: TTL, traceroute and ICMP types

  • Lab: Docker container with namespaces pc, r1, r2, srv on 192.168.57.0/24 split into /26 links; r1-r2 link MTU 1400.
  • Normal ping shows ttl=62 (two routers took one each off 64).
  • ping -t 1 sets TTL 1: router 1 answers Time to live exceeded.
  • tcpdump on the PC captures echo request, time exceeded, host unreachable and UDP port unreachable.
Terminal
ping -c 2 192.168.57.130ping -c 1 -t 1 192.168.57.130traceroute -n -q 1 192.168.57.130tcpdump -n -i eth0 icmp
Output
$ ping -c 2 192.168.57.13064 bytes from 192.168.57.130: icmp_seq=1 ttl=62 time=0.200 ms64 bytes from 192.168.57.130: icmp_seq=2 ttl=62 time=0.104 ms2 packets transmitted, 2 received, 0% packet loss$ ping -c 1 -t 1 192.168.57.130From 192.168.57.1 icmp_seq=1 Time to live exceeded1 packets transmitted, 0 received, +1 errors, 100% packet loss$ traceroute -n -q 1 192.168.57.130traceroute to 192.168.57.130, 30 hops max 1  192.168.57.1  0.011 ms 2  192.168.57.66  0.006 ms 3  192.168.57.130  0.006 ms$ tcpdump -n -i eth0 icmp192.168.57.10 > 192.168.57.130: ICMP echo request192.168.57.1 > 192.168.57.10: ICMP time exceeded in-transit192.168.57.66 > 192.168.57.10: ICMP time exceeded in-transit192.168.57.66 > 192.168.57.10: ICMP host 192.168.57.140 unreachable192.168.57.130 > 192.168.57.10: ICMP 192.168.57.130 udp port 33437 unreachable

37.5 MTU, fragmentation and Path MTU discovery

  • MTU (Maximum Transmission Unit) = maximum size of one packet on a link; Ethernet is 1500 bytes. VPN links are often smaller (1400 in the lab).
  • Fragmentation: with DF off, router 1 splits a 1500-byte packet into two fragments and the server reassembles them.
  • Fragmentation is costly: lose one fragment and the whole packet is resent.
  • Path MTU Discovery: the sender sets DF (Don't Fragment); a router that cannot forward replies ICMP type 3 code 4 with the next-hop MTU; the sender caches it.
Path MTU discovery (DF + ICMP)
  1. 1.PC sends a 1500-byte packet with the DF flag set

  2. 2.Router 1's next link (r1-r2) has MTU 1400

  3. 3.Router 1 drops it, sends ICMP type 3 code 4: fragmentation needed, mtu 1400

  4. 4.PC caches path MTU 1400 for this destination

  5. 5.PC now sends 1400-byte packets that reach the server without fragments

ItemSize
Ethernet MTU1500 bytes
IPv4 header20 bytes
ICMP header8 bytes
Max DF ping payload at MTU 15001500 - 20 - 8 = 1472
Max DF ping payload at MTU 14001372

37.6 Practical: MTU test with a DF ping (Linux)

  • -M do sets DF; -s 1472 makes a 1500-byte packet; router 1 answers Frag needed and DF set (mtu = 1400).
  • ip route get shows the cached path MTU (expires in ~10 minutes).
  • -s 1372 makes exactly 1400 bytes and gets a reply.
  • -M dont (DF off) with 1472 also gets a reply, but tcpdump on the server shows two fragments.
  • tracepath finds the path MTU without root: Resume: pmtu 1400 hops 3.
Terminal
ping -c 1 -M do -s 1472 192.168.57.130ip route get 192.168.57.130ping -c 1 -M do -s 1372 192.168.57.130ping -c 1 -M dont -s 1472 192.168.57.130tracepath -n 192.168.57.130
Output
$ ping -c 1 -M do -s 1472 192.168.57.130PING 192.168.57.130 1472(1500) bytes of data.From 192.168.57.1 icmp_seq=1 Frag needed and DF set (mtu = 1400)$ ip route get 192.168.57.130192.168.57.130 via 192.168.57.1 dev eth0    cache expires 595sec mtu 1400$ ping -c 1 -M do -s 1372 192.168.57.130PING 192.168.57.130 1372(1400) bytes of data.1380 bytes from 192.168.57.130: icmp_seq=1 ttl=621 packets transmitted, 1 received, 0% packet loss$ ping -c 1 -M dont -s 1472 192.168.57.1301480 bytes from 192.168.57.130: icmp_seq=1 ttl=62srv$ tcpdump -n -v -i eth0 icmpIP (ttl 62, id 38881, offset 0, flags [+], length 1396)  192.168.57.10 > 192.168.57.130: ICMP echo requestIP (ttl 62, id 38881, offset 1376, flags [none], length 124)  192.168.57.10 > 192.168.57.130: ip-proto-1IP (ttl 64, id 18375, offset 0, flags [none], length 1500)  192.168.57.130 > 192.168.57.10: ICMP echo reply$ tracepath -n 192.168.57.130 1?: [LOCALHOST]          pmtu 1500 1:  192.168.57.1         0.119ms 2:  192.168.57.1         0.033ms pmtu 1400 2:  192.168.57.66        0.037ms 3:  192.168.57.130       0.036ms reached     Resume: pmtu 1400 hops 3 back 3

Fragment 1: offset 0, length 1396, flag [+] (more fragments). Fragment 2: offset 1376, length 124. Same id 38881 ties them together.

37.7 Practical: Windows ping -f -l

  • -f sets DF, -l sets the payload size.
  • To 8.8.8.8: 1452 works, 1453 times out, so path MTU = 1452 + 28 = 1480 bytes.
  • No fragmentation error came back here, only a timeout (the ICMP message was not delivered).
Output
ping -n 2 -f -l 1472 8.8.8.8ping -n 2 -f -l 1452 8.8.8.8ping -n 2 -f -l 1453 8.8.8.8
Output
$ ping -n 2 -f -l 1472 8.8.8.8Pinging 8.8.8.8 with 1472 bytes of data:Request timed out.Request timed out.$ ping -n 2 -f -l 1452 8.8.8.8Pinging 8.8.8.8 with 1452 bytes of data:Reply from 8.8.8.8: bytes=1452 time=22ms TTL=117Reply from 8.8.8.8: bytes=1452 time=22ms TTL=117$ ping -n 2 -f -l 1453 8.8.8.8Pinging 8.8.8.8 with 1453 bytes of data:Request timed out.Request timed out.    Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),

37.8 Common mistakes

PMTU black hole: why blocking all ICMP breaks things
  1. 1.Server sends a big response with DF set

  2. 2.VPN router's link MTU is smaller: it drops the packet

  3. 3.Router sends ICMP fragmentation needed back

  4. 4.Firewall blocks all ICMP, so the message never reaches the server

  5. 5.Server keeps resending the same big packet -> download hangs

  • Blocking all ICMP 'for safety': to block ping, block only echo request and keep types 3 and 11 allowed.
  • Forgetting the 28 bytes of headers when calculating a DF ping payload.
  • Treating a * in traceroute as a failure: many routers rate-limit ICMP replies.
  • Not checking MTU first when a download hangs on a VPN.

37.9 Interview tips

  • Traceroute: probes with TTL 1, 2, 3...; each router replies ICMP Time Exceeded (type 11) when TTL hits 0.
  • Path MTU Discovery: DF flag + ICMP Fragmentation Needed (type 3, code 4) carrying the next-hop MTU.
  • Reply ttl=57 from Linux (starts at 64) -> 7 routers in between.
  • MTU 1500 -> max DF ping payload 1472 (20 IP + 8 ICMP).
  • PMTU black hole = ICMP type 3 blocked; symptom is hanging transfers, small requests still work.