MTU mismatch over WireGuard: HTTPS hangs but ping works fine
I lost most of a Tuesday to this one, and the worst part is that every basic check passed.
We had a small site-to-site WireGuard tunnel between an office router and a VM in a colo. SSH worked. DNS worked. curl to an internal API sometimes returned headers in about two seconds and sometimes sat there until the timeout. Bigger responses never came back at all. The app people called it the network being slow, which was not wrong but was not useful either.
## The symptom that gave it away
Small requests worked, large ones died. That is almost always fragmentation or MTU. A TLS handshake fits in one packet; a JSON response with a few hundred rows does not.
The client side was Ubuntu 22.04 with WireGuard tools 1.0.20220627. The tunnel interface reported 1420, which is what wg-quick sets by default for a link it thinks is 1500:
$ ip link show wg0
4: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/none
1420 looked reasonable. It was also wrong for our path.
## Finding the real limit
The test that settled it was a sweep with ping and the do-not-fragment bit. On Linux the payload size you pass to -s plus 28 bytes of IP and ICMP headers has to fit:
$ ping -M do -s 1472 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 1472(1500) bytes of data.
ping: local error: message too long, mtu=1500$ ping -M do -s 1464 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 1464(1492) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=62 time=18.4 ms
1492. PPPoE. The office uplink was doing PPPoE and nobody had told the tunnel. The colo side was a clean 1500, so the path MTU was the smaller of the two.
## Why PMTUD did not save us
Path MTU discovery relies on routers sending back ICMP fragmentation-needed messages. Ours were being dropped. Plenty of firewalls still block ICMP type 3 code 4 because someone once read that all ICMP is dangerous. The result is a black hole: the sender keeps retransmitting a too-large segment, the router quietly drops it, and the application just sees a stall.
The literal curl error we kept getting was:
curl: (28) Operation timed out after 30001 milliseconds with 0 bytes received
Zero bytes. Not a slow response, no response.
## The fix, and the part that surprised me
We set the tunnel MTU explicitly and clamped TCP MSS on the forwarding rules:
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.0.0.2/32
MTU = 1380
PostUp = iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
PostDown = iptables -D FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
1380 is deliberately 40 bytes under the 1420 ceiling, accounting for the outer IPv4 header and the WireGuard overhead on top of PPPoE framing. I went conservative on purpose; an MTU that is too small costs a few bytes per packet, an MTU that is too large costs a support ticket.
Surprise: wg-quick has an MTU setting, but if you also have PostUp scripts rewriting routes you can end up with a route whose advertised MSS disagrees with the link. Check both with ip route show table all | grep wg0. I had to add advms 1380 to one route by hand.
After the change the same 300-row request came back in 400 ms. The API team never did anything. I still check -M do on any new tunnel before I let anyone use it.