lab.awk.im

WireGuard MTU: when ping works and nothing else does

· wireguard, networking

The symptom is always the same: the tunnel is up, ping works, SSH logs in, and then git clone hangs or a web page loads half way. Small packets fit, big ones do not.

The arithmetic

WireGuard adds 32 bytes of its own plus the outer UDP and IP headers:

UnderlayOverheadMax inner MTU on a 1500 link
IPv420 + 8 + 32 = 601440
IPv640 + 8 + 32 = 801420

wg-quick defaults to 1420 so it works over either. Over PPPoE (1492) that becomes 1412, and over another tunnel it shrinks again. When in doubt, start at 1280 and work up.

Finding the real limit

Ping with the don't-fragment bit set. The ICMP payload plus 28 bytes of IPv4/ICMP headers is the packet size:

# through the tunnel: 1392 + 28 = 1420
ping -M do -s 1392 10.8.0.1
# too big? lower -s until it passes, then set MTU = size + 28

Clamp MSS for routed traffic

For hosts behind the tunnel that you do not control, clamp TCP MSS on the forwarding box so their SYNs advertise a size that fits:

table inet mss {
	chain forward {
		type filter hook forward priority mangle; policy accept;
		oifname "wg0" tcp flags syn tcp option maxseg size set rt mtu
	}
}

And keepalive for NAT

A peer behind NAT goes silent after the mapping expires. On that peer:

[Peer]
PersistentKeepalive = 25

Twenty-five seconds is the conventional value and well under every NAT timeout I have met.