I'd like to connect to my server which is behind the NAT through mosh. I can't touch the router to set it as upnp support, but I've apply for a UDP port forward 9807->60000, and a ssh port forward of cause.
So, is there anyway to specified the server port through command line args or conf file at client and/or server side?
Note: the following not work!!
mosh -p 9807 user@my_server
Edit:
I've try to ssh to my server first, and run mosh-server -p 60000 manually, and then mosh -p 9807 my_server from another terminal. This cause an error:
Error binding to IP my_server_ip: bind: Address already in use
That said:
Thanks.
For Mosh to work, the server needs to have Mosh binaries installed. This doesn't run a daemon like sshd ; rather, it's the first command your Mosh client runs when connecting over SSH. When the connection closes, the server terminates the running Mosh server.
Mosh (mobile shell) is a remote terminal application that supports intermittent connectivity, allows roaming, and speculatively and safely echoes user keystrokes for better interactive response over high-latency paths.
The problem you're having lies in the port redirection. Your NAT forward at the router is sending incoming traffic sent to <domain>:9807
on to <internal-ip>:60000
. When you start mosh with the -p
option, the client connects to the server over ssh and tells the server to start, listening on the port specified. The mosh-server then communicates the open port number (in this case, the one you specified) back to the client, which closes the ssh connection and tries to connect to <domain>:<port>
. The client is trying to communicate to the same port the server is listening on. The problem is that your NAT router is redirecting traffic from one port on the WAN side to a different port on the NAT'd machine. This will not work.
The best thing to do would be to get a direct translation, such as requesting the router forward port 9807 on the WAN side to your mosh-server machine at port 9807.
If that is not an option, the next best thing I can think of is to mangle the traffic on the server machine using iptables.
iptables -t nat -A PREROUTING -p udp --dport 60000 -j REDIRECT --to-port 9807
The execute your client as you describe
mosh -p 9807 user@my_server
What happens is:
mosh-server
listening on port 9807
.9807
9807
9807
and sends it to your server at port 60000
60000
over UDP
, which matches the iptables rule and get redirected to their destination (the server's IP, in this case), but at port 9807
Let me suggest the following proof-of-concept method of connecting to mosh server behind NAT. Lets say we have the following computers:
ssh -R ... relay_host
on the server may help.So we do:
relay_host> udprelay 0.0.0.0 34730 34731
Port numbers mentioned above are hardcoded into the client script, but they could be easily changed. Also note, that udprelay is dramatically insecure at the moment.socat
tool is also installed there.client_host> mosh-nat-client.sh SERVER_SSH_NAME RELAY_IP
This script calls server_host with ssh SERVER_SSH_NAME <mosh-nat-server.sh ARGS>
, records the key and uses it to run the mosh-client. The tricky part of it is to punch a hole in server's NAT and let both sides met at udprelay
.See also a nice blog post describing a slightly different situation. In the above terms, it shows how to connect from relay_host to server_host. Author doesn't use udp relays but he still needs bulky LD_PRELOAD
machinery. Surprisingly, it does it's job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With