English
简体中文繁體中文EnglishРусскийفارسی

Home › Blog › Speed

Too thick for the letter slot

Ping works over WireGuard but pages, SSH or images hang? It is usually the MTU. How to measure the right value with ping and clamp the MSS.

Compiled on

The slot in the door is only this wide
The slot in the door is only this wide Gazamp, CC BY-SA 4.0

Ping works and small pages open, but pictures spin and SSH freezes at the first command. The link is up; large packets do not fit.

The most annoying fault, because it looks like a slow line. Speed tests open, messages are sent, pictures spin forever; ssh logs in and stops at the first long output. Small packets pass, large ones vanish.

Why

Every stretch of line has a largest packet. WireGuard adds 60 or 80 bytes, and what exceeds the limit is dropped. Routers should answer "too big", but many networks drop that answer, so the sender waits.

A letter slot: a thick envelope will not fit, nor will an oversized packet
A letter slot: a thick envelope will not fit, nor will an oversized packet Alex Grech from Malta, CC BY 2.0

Measure it

On Windows, find the largest that passes
ping -f -l 1472 1.1.1.1
ping -f -l 1464 1.1.1.1
ping -f -l 1372 1.1.1.1

The largest that works plus 28 is the line MTU; subtract 80 and write that down. Or use the MTU tool.

Change it

In [Interface] on both ends
MTU = 1380
NetworkTry first
Ordinary fibre1420
PPPoE1412
Mobile data1320
Still failing1280

1280 is the least IPv6 allows and passes almost anywhere, at some cost in speed.

A standard envelope: lowering MTU is choosing an envelope that fits
A standard envelope: lowering MTU is choosing an envelope that fits Donald Trung Quoc Don, CC BY-SA 4.0

On a gateway

Devices behind it do not know about the tunnel and send 1500. Rewrite the TCP MSS on the gateway:

Linux gateway
iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

Why some sites and not others

Both ends agree on a segment size when a page opens. Some sites set it low and happen to fit; others use the usual 1460, which is too large once the tunnel's wrapper is added. Transfers behave alike: a few small packets pass, then full ones start and it hangs at some percentage.

The arithmetic

PartIPv4IPv6
Outer IP header2040
UDP header88
WireGuard header and check3232
Total6080

On a 1500 line IPv4 allows 1440 and IPv6 1420, hence the default of 1420. PPPoE leaves 1492, so 1412. Another tunnel at the provider takes more.

Find the limit with ping

Halve the interval: try 1400; if it passes 1436, if not 1300. Five or six tries are enough. Test with WireGuard off, because you measure the line beneath.

macOS and Linux
ping -D -s 1400 1.1.1.1            # macOS
ping -M do -s 1400 1.1.1.1         # Linux

Message too long or silence both mean no.

Which end to change

The sender decides. When you download, the large packets come from the server, so changing only your computer may do nothing. Write the same value on both sides.

Try first, without editing
sudo ip link set dev wg0 mtu 1380

It takes effect at once and disappears with the interface.

A house full of devices behind a gateway

Devices behind a WireGuard router do not know about the tunnel and send 1500. The "too big" answers are often lost, so the gateway has to rewrite the number when TCP connects: the --clamp-mss-to-pmtu rule above. In OpenWrt it is a checkbox called MSS clamping in the firewall zone. It only concerns TCP; QUIC finds out for itself.

When it is not the MTU

  • Everything is slow, large or small: the line or the server's bandwidth.
  • Only in the evening: see throttled UDP.
  • One site only, for others too: it blocks this IP.
  • Loss: ping -n 200; a few percent is enough to stall pages.
Why are phones rarely affected?

The mobile apps default to a smaller value.

Is smaller always better?

No. More packets mean less speed. The largest that works is best.

Can I just set 1280?

Yes, it costs a few percent of speed. Many people do.

Does the server need a restart?

No, only the interface. Remotely, write down and up on one line so you do not lock yourself out.

Is it different over IPv6?

The wrapper is 20 bytes larger. If the same profile uses either, leave room for IPv6.

Next letter

On the same round

Postcodes: WireGuard slow pages, WireGuard MTU problem, WireGuard SSH hangs