Sub topic 4
Overhead, MTU and fragmentation
This chapter assumes you know IP addressing and subnets, how a routing table and default route work, the difference between TCP and UDP, and basic Linux command-line use. It covers why tunnels shrink the usable packet size and how that breaks traffic in confusing ways.
Why a tunnel shrinks your packets
Every link has a maximum transmission unit (MTU). This is the largest IP packet, headers included, that the link can carry in one piece. Ethernet usually has an MTU of 1500 bytes.
Encapsulation puts the original packet inside a new one. The new outer packet needs its own headers, so the inner packet has less room. The outer packet still has to fit in the 1500 bytes of the physical link.
| Tunnel | Typical added overhead | Inner MTU on a 1500-byte link |
|---|---|---|
| GRE over IPv4 | 24 bytes (20 IP + 4 GRE) | 1476 |
| WireGuard over IPv4 | 60 bytes (20 IP + 8 UDP + 32 WireGuard) | 1440 |
| WireGuard over IPv6 | 80 bytes | 1420 |
| IPsec ESP (tunnel mode) | about 50 to 70 bytes, varies with cipher and padding | about 1430 to 1450 |
The tunnel interface advertises its own smaller MTU. Hosts that respect it send smaller packets. Problems start when something along the path does not.
Fragmentation and the Don't Fragment bit
When a packet is too big for a link, a router can fragment it into smaller pieces, and the destination reassembles them. Fragmentation is costly. If one fragment is lost, the whole packet is lost. Many firewalls also drop fragments.
IPv4 senders can set the Don't Fragment (DF) bit. A router that cannot forward a DF packet drops it and returns an ICMP "Fragmentation needed" message, which includes the next-hop MTU. The sender then lowers its packet size. This process is called Path MTU Discovery (PMTUD). IPv6 routers never fragment, so PMTUD is always in use there.
The MTU black hole
PMTUD depends on ICMP messages arriving. Some firewalls block all ICMP. Then large packets are dropped and the sender never learns why. This is an MTU black hole.
The typical symptom is a mix of working and failing traffic:
- Ping works, because its packets are small.
- The TCP handshake completes, because those packets are small.
- Small web pages load, but large downloads or TLS handshakes with big certificates hang.
- SSH logs in, then freezes when you list a large directory.
Testing the path
Send pings with DF set and vary the size. The payload size plus 28 bytes (20 IP, 8 ICMP) gives the packet size.
ping -M do -s 1372 10.8.0.1This sends a 1400-byte packet. If it succeeds, try a larger size. If you get "message too long" or no reply, lower it. Repeat until you find the largest size that passes. Add 28 to get the path MTU.
Fixes
There are three common approaches:
- Set the tunnel interface MTU explicitly, for example
ip link set dev gre1 mtu 1400, so that hosts send smaller packets. - Clamp the TCP maximum segment size (MSS). A router rewrites the MSS in TCP handshakes so both ends send segments that fit. This only helps TCP.
- Allow the needed ICMP messages through firewalls (ICMP type 3 code 4 for IPv4, "Packet Too Big" for IPv6).
On a Linux gateway, MSS clamping looks like this:
sudo iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtuExercise
A WireGuard tunnel runs over IPv4 on a 1500-byte link. Pings through it work, and web pages with little content load, but large file downloads stall. What is the likely cause, what MTU does the tunnel interface need at most, and how would you confirm the problem?
Show answer
The likely cause is an MTU black hole. Full-size 1500-byte inner packets become 1560-byte outer packets, and ICMP "Fragmentation needed" messages are probably blocked, so the sender never reduces its size. WireGuard over IPv4 adds 60 bytes, so the tunnel MTU must be at most 1440. To confirm, run ping -M do -s N through the tunnel with decreasing N. Packets of 1440 bytes or less (payload 1412 or less) should pass, and larger ones should fail. The fix is to set the tunnel MTU to 1440 or lower, clamp the TCP MSS, or allow the ICMP messages.