Last Updated: February 25, 2016
· sheerun
Photo on 08.01.2013 at 04.15

Allow for selecting interface when port forwarding

According to sshd_config, the GatewayPorts option:

Specifies whether remote hosts are allowed to connect to ports forwarded for the client. By default, sshd(8) binds remote port forwardings to the loopback address. This prevents other remote hosts from connecting to forwarded ports. GatewayPorts can be used to specify that sshd should allow remote port forwardings to bind to non-loopback addresses, thus allowing other hosts to connect. The argument may be “no” to force remote port forwardings to be available to the local host only, “yes” to force remote port forwardings to bind to the wildcard address, or “clientspecified” to allow the client to select the address to which the forwarding is bound. The default is “no”.

So to enable selecting binding interface for port forwarding it's enough to add following ling to sshd_config:

GatewayPorts clientspecified

And restart sshd:

sudo restart ssh

Now you can forward port on local interface:

ssh user@example.com -R

Or on Internet-connected one:

ssh user@example.com -R

Bonus: my step by step understanding how to set up SSH tunneling

Say Thanks
Filed Under