Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to forward sshd (port 22) on machine X which has a non-routeable IP. The forwarding options are nc (which is horrible), inetd (requires privs), iptables (requires privs) and ssh. So I'm using ssh, which has the added bonus of providing an encrypted tunnel.

I have a machine Y with a public IP. I want to expose X:22 as Y:8022.

X $ ssh -R8022:localhost:22 Y

This works, but port 8022 is bound to the loopback:

Y $ netstat -ant
. . .  
tcp        0      0*               LISTEN

which means I cannot connect from any foreign machines. Since GatewayPorts is no in Y's /etc/ssh/sshd_config, I cannot specific another bind address. Any ideas?

Note: I did manage to get things working by using another tunnel from Y to Y:

Y $ ssh -g -L9022:localhost:8022 localhost

which is a very inefficient solution: it encrypts/decrypts on localhost from port 9022 to 8022, then encrypts again before sending to X. Surely there must be a better way?

share|improve this question
Possible duplicate of How to make ssh tunnel open to public? – Cees Timmerman Mar 9 at 12:28

Why do you use a reverse port forwarding?

On host Y:

ssh -f -N -q -L 8022:localhost:22 user@X should do the trick

-f: daemonize

-N: no command

-q: quiet

-L: port forward

share|improve this answer
You can ssh from Y to X because (as noted in the question), X has a private IP. This means a reverse tunnel is required. – Fixee Apr 13 '13 at 20:14
ok, since GatewayPorts is off, i haven't any solution...sorry – maxxvw Apr 13 '13 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .