I want to connect to Server A which is behind a NAT and a firewall which blocks all incoming connections. I want to access port 9000. In my office I have a public IP and control of the router. My idea is to run autossh on Server A which establishes a tunnel to Server B in my office. Then use another autossh tunnel to go back and forward port 9000 to 9001. I feel like I'm halfway there.

On the remote server, I have a systemd service running:
autossh -M 0 -q -N -p 22 -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -R :2222:localhost:22 elliott@xxx.xxx.xxx.xxx

Now I can connect to Server B from my laptop with
ssh elliott@ -p 2222

I'm trying to forward the port like this:
ssh elliott@ -p 2222 -L :9001:localhost:9000 -N

So now I expect I can connect from my laptop to but I get connection refused.


You should connect to port 9001 on your laptop (likely localhost) and this will forward the connection to port 9000 on your ssh endpoint.

BTW, you can also modify your autossh the following way:

autossh -M 0 -q -N -p 22 -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -R :2222:localhost:22 -R :9001:localhost:9000 elliott@xxx.xxx.xxx.xxx

and connect to port 9001 on and this will forward to port 9000 on ssh client.

I assume you realize this may be an offense resulting in termination.

  • Doh! Of course, that was it. I did not realize you can have more than on -R flag, that actually seems like a better way. What do you mean about an offense, is there some security issue with this? – Elliott B Jun 6 '19 at 20:20
  • 1
    There certainly is a reason why the firewall blocks incoming connections (whether it makes sense or not is irrelevant). Punching a hole like this in FW may be considered a security breach and such things usually end up in employment termination. – Tomek Jun 6 '19 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.