Strovent SystemsSign in
Reference

Mosh behind NAT, with IPv6, or when the server's address changes

Mosh survives your own address changing and works through typical NAT, but it uses one server address for the whole session. What that means for IPv6.

Mosh is known for surviving network changes. That is true for your side: the client can move from Wi-Fi to mobile data and back. The server side is fixed when the session starts. Knowing the difference explains most NAT and IPv6 questions.

Your address can change; the server's cannot

The server accepts each authenticated datagram from whatever address it comes from, so the session follows you when your phone or laptop changes network. See How Mosh works.

The other way round does not work. The Mosh manual says that at session start Mosh selects a single IPv4 or IPv6 server address and uses it for the lifetime of the session. If the server's address changes, for example a home server whose ISP gives it a new address, the client keeps sending to the old one and the session stops getting updates. Start a new session to the new address; tmux or screen on the host keeps your work in the meantime (Keep your work after a disconnect with tmux, and attach automatically).

NAT

The manual says Mosh works through typical client-side network address translators, but UDP must pass between client and server.

On the server side, NAT needs a UDP port forward: forward a port such as 60001 to the server and start Mosh with -p 60001, because without a forward the server cannot be reached on its random port between 60000 and 61000. See Mosh "Nothing received from server on UDP port 60001".

--bind-server controls which address mosh-server replies from. The default, ssh, uses the address the SSH connection came in on, which suits servers with several addresses. --bind-server=any is for setups where the SSH connection appears to come from localhost, such as through sslh.

IPv6 and dual-stack hosts

The manual describes Mosh's IPv6 support as limited. The --family option picks the address family for both the SSH login and the Mosh session:

  • --family=prefer-inet (the default): try the IPv4 addresses first.
  • --family=prefer-inet6: try IPv6 first.
  • --family=inet (-4) or --family=inet6 (-6): one family only.
  • --family=all: any address; the manual says this needs Mosh 1.2.5 or later on the server when roaming with dual-stack servers.

If Mosh works over one family but not the other, a firewall may be letting UDP through for one of them only. Try -4 and -6 to find out.

-p, --bind-server and --family (-4, -6) are options of the mosh command on a computer. This app's Mosh connection has no settings for them.

Sources

Spotted a mistake? Email [email protected].