Strovent SystemsSign in
Reference

Mosh works on Wi-Fi but freezes or fails through a VPN: the MTU

Mosh over a VPN can connect, then freeze when a lot of output arrives. Why large UDP datagrams get lost in the tunnel, how to test the path, and what to change.

Mosh connects and works on your home Wi-Fi. Over the company VPN, or a hotel network with the VPN on, it either never connects or it connects and then freezes: typing still echoes, but a command with a lot of output never finishes drawing, and the standard mosh client shows a "mosh: Last contact ... seconds ago" banner.

There are two different causes. Find which one you have first.

It never connects: UDP does not get through

If Mosh stops with "Nothing received from server on UDP port 60001", the VPN or a firewall behind it is not passing Mosh's UDP traffic at all. Some VPNs only carry the traffic their policy allows, and the server's firewall may only expect UDP from the internet, not from the VPN's address range. See Mosh "Nothing received from server on UDP port 60001".

It connects, then stalls: packets too big for the tunnel

Mosh sends the screen in UDP datagrams. Small ones (your keystrokes, a short reply) get through. When the screen changes a lot, Mosh sends datagrams close to its maximum size. Since Mosh 1.2.6 that maximum is 1280 bytes for IPv4; earlier versions used 1380.

A VPN wraps each packet in its own header, so less room is left. Mosh clears the "don't fragment" flag, so an oversized datagram should be split into fragments and put back together at the other end. Some VPNs and networks drop the fragments, or the large packets, instead. The small packets keep arriving, the large ones never do, and the screen stops updating. Mosh does not probe the path for a smaller size on its own.

Users in the Mosh issue tracker have reported this with Cisco AnyConnect, with a VPN tunnel limited to about 1100 bytes, and with a train Wi-Fi network that dropped tunnelled packets of 1320 bytes or more.

Test the path

Send pings that must not be fragmented, and lower the size until they get through. The size is the data part; IPv4 and ICMP headers add 28 bytes.

ping -M do -s 1252 host.example.com     Linux
ping -D -s 1252 host.example.com        macOS and BSD
ping -f -l 1252 host.example.com        Windows

If 1252 (a 1280-byte packet) fails over the VPN but works without it, the tunnel cannot carry Mosh's largest datagrams.

What to change

  • Update Mosh on the server (and on the client if it is a separate program) to 1.2.6 or later, for the smaller 1280-byte size.
  • Ask whoever runs the VPN whether it can pass fragmented UDP, or use a larger tunnel MTU.
  • Lower Mosh's size on the server. The maximum is a constant in Mosh's source (DEFAULT_IPV4_MTU in src/network/network.h). Users with small tunnels have rebuilt mosh-server with a smaller value, such as 1072, and reported that the stalls stopped. 1024 has been suggested in the tracker as a value that works almost everywhere.
  • Use SSH for that network, with tmux on the host so you can carry on later. See Mosh or SSH?.

Sources

Spotted a mistake? Email [email protected].