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 also builds on the previous chapters' idea of encapsulation: a tunnel wraps an inner packet in an outer packet.
Why tunnels shrink your packets
Every encapsulation layer adds header bytes. A physical Ethernet link usually carries at most 1500 bytes of IP packet. That limit is the MTU (maximum transmission unit), the largest IP packet an interface can send without splitting it.
A tunnel must fit the whole inner packet, plus the new outer headers, into one outer packet. If the outer path allows 1500 bytes and the tunnel adds 24 bytes, the inner packet can be at most 1476 bytes. The tunnel interface therefore needs a smaller MTU than the physical interface under it.
|<-------------- outer packet: 1500 bytes max -------------->|
| outer IP | tunnel header | inner IP packet (max = tunnel MTU) |The rule is: tunnel MTU = underlying path MTU - tunnel overhead. If you ignore it, large packets break while small ones keep working. That symptom is the main reason tunnels get a reputation for being flaky.
How much overhead each protocol adds
The figures below assume an outer IPv4 header of 20 bytes and no IP options. Real values depend on the cipher, the padding and whether NAT traversal is in use.
| Encapsulation | Added bytes (approx.) | Typical tunnel MTU on a 1500-byte path |
|---|---|---|
| GRE over IPv4 | 20 outer IP + 4 GRE = 24 | 1476 |
| WireGuard over IPv4 | 20 IP + 8 UDP + 16 header + 16 auth tag = 60 | 1440 |
| WireGuard over IPv6 | 40 IP + 8 UDP + 16 header + 16 auth tag = 80 | 1420 |
| IPsec ESP, tunnel mode | 20 IP + 8 ESP header + 8 to 16 IV + padding + 2 trailer + 12 to 16 integrity tag, about 50 to 73 | about 1430 or less |
| IPsec ESP with NAT-T | the ESP figure + 8 for the UDP header | about 1420 or less |
| OpenVPN over UDP | varies with cipher and options | set by `tun-mtu` and `mssfix` |
WireGuard's default interface MTU is 1420. That value is safe over both IPv4 and IPv6 on a 1500-byte path, so it works without tuning in most cases.
ESP padding makes IPsec overhead vary from packet to packet. The cipher's block size and the ESP alignment rules decide how many padding bytes each packet gets.
What happens when a packet is too big
When a router must forward a packet larger than the next link's MTU, IPv4 and IPv6 behave differently.
- IPv4, Don't Fragment (DF) bit clear: the router splits the packet into fragments. The destination reassembles them. This works, but it costs CPU and any lost fragment forces the whole packet to be resent.
- IPv4, DF bit set: the router drops the packet and sends back an ICMP "Fragmentation needed" message (type 3, code 4) that includes the next-hop MTU.
- IPv6: routers never fragment. They drop the packet and return ICMPv6 "Packet Too Big" (type 2). Only the sending host may fragment.
Hosts use the DF bit plus those ICMP messages for Path MTU Discovery (PMTUD). The sender starts with a large packet, learns the real limit from the error and lowers its packet size. TCP sets DF on nearly all its segments, so it relies on PMTUD.
Fragmenting the outer packet versus the inner packet
A tunnel endpoint has two choices when an inner packet is too big for the outer path.
- Fragment the inner packet before encapsulating it. Each piece is then tunnelled separately.
- Encapsulate first, then fragment the outer packet. The far endpoint must reassemble the outer fragments before it can decapsulate them.
Both work, but both are costly. Reassembly needs buffers, and middleboxes often drop fragments. Many firewalls and NAT devices treat non-first fragments badly because they carry no UDP or TCP port numbers. Prefer a correct tunnel MTU so that fragmentation never happens.
The PMTUD black hole
A black hole is a path where large packets vanish with no error. It happens when the router that drops an oversized DF packet is unable to tell the sender, or when the ICMP error is filtered before it arrives.
The classic symptom is a TCP connection that completes its handshake, because SYN packets are tiny, and then hangs when real data flows. SSH logins freeze after the banner. HTTPS connects but large pages never finish loading. ping with default small packets works fine.
Two common causes:
- A firewall that drops all ICMP "to be safe". Blocking ICMP type 3 code 4 and ICMPv6 type 2 breaks PMTUD. Never block them.
- A tunnel endpoint that does not generate its own ICMP error for inner packets with DF set, so the inner sender never learns that the tunnel MTU is smaller.
Fix 1: set the tunnel MTU correctly
Check the current MTUs and set the tunnel interface to the right value. For the GRE tunnel from the earlier chapter, over a 1500-byte path:
ip link show dev gre1
sudo ip link set dev gre1 mtu 1476
ip link show dev gre1With the interface MTU set, Linux can generate the ICMP error itself when an inner packet is too big. The inner sender then adjusts. For WireGuard, set MTU = 1380 or similar in the [Interface] section if the underlying path is smaller than 1500, for example on a PPPoE link (1492) or a cellular network.
Fix 2: clamp the TCP MSS
The MSS (maximum segment size) is the largest TCP payload a host will accept in one segment. Each side announces its MSS in the SYN packet. For IPv4 without options, MSS = MTU - 40 (20 for IP, 20 for TCP).
MSS clamping rewrites the MSS in SYN packets that cross the tunnel, so both hosts agree on a size that already fits. This works even when ICMP is blocked, because the sender never creates packets that are too big.
sudo iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
-o gre1 -j TCPMSS --clamp-mss-to-pmtu--clamp-mss-to-pmtu sets the MSS from the MTU of the outgoing interface. Apply the same rule for traffic leaving through the other direction of the tunnel, using -i gre1 on the return path if needed.
MSS clamping only helps TCP. UDP traffic, such as DNS responses or QUIC, is not touched. Use it as a safety net on top of a correct MTU, not instead of one.
Finding the real path MTU
Test with ping and the DF bit. The -s value is the ICMP payload size, and the packet is 28 bytes larger (20 IP + 8 ICMP). So -s 1372 produces a 1400-byte packet.
ping -M do -s 1372 10.8.0.1-M do sets the DF bit and forbids local fragmentation. If this reply comes back, the path carries 1400-byte packets. If you see "message too long" or no reply, lower -s and retry until it passes. The largest working packet size is the path MTU.
You can also let the system search for you:
tracepath -n 10.8.0.1tracepath reports pmtu values as it discovers them along the path. It needs no root privileges.
Test through the tunnel and over the raw underlay separately. If the underlay carries 1500 bytes but the tunnel fails at 1400, the overhead is larger than you assumed, perhaps because of NAT-T, IPv6 outer headers or an extra encapsulation layer such as PPPoE.
Common errors
| Symptom | Likely cause | Check |
|---|---|---|
| Handshake succeeds, then the connection hangs | PMTUD black hole | `ping -M do` with growing sizes |
| Small web pages load, large ones stall | MTU too high, ICMP blocked | Add MSS clamp, then lower the MTU |
| Throughput far below link speed | Heavy fragmentation and reassembly | Look for fragments in `tcpdump` |
| Works over wired, breaks over mobile or PPPoE | Underlay MTU below 1500 | Measure underlay MTU first |
| UDP apps fail, TCP works | MSS clamp hides the problem for TCP only | Test with UDP of known size |
| Tunnel inside a tunnel fails | Overheads add up | Subtract each layer in turn |
Nested tunnels deserve a note. Each layer subtracts its own overhead. A WireGuard tunnel carried inside IPsec with NAT-T on a 1500-byte link leaves well under 1400 bytes for the innermost packet. Work from the physical link inward and subtract each layer.
Exercise
A GRE tunnel over IPv4 runs on a path whose MTU is 1492 because of PPPoE. What MTU should the tunnel interface have, and what TCP MSS should be clamped for IPv4 traffic through it?
Show answer
GRE over IPv4 adds 24 bytes (20 outer IP + 4 GRE). Tunnel MTU = 1492 - 24 = 1468. TCP MSS = 1468 - 40 = 1428 (20 bytes IP + 20 bytes TCP header, no options).
Exercise
SSH over a new VPN connects and shows the login banner, then freezes. ping 10.8.0.1 works. What is the likely cause, and what single command tests it?
Show answer
Most likely a PMTUD black hole: small packets (handshake, banner) pass, but larger packets with DF set are dropped and the ICMP error does not return. Test with ping -M do -s 1372 10.8.0.1 and lower -s until replies return. The largest working size shows the usable path MTU.