Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make SSH remote port forward that listens 0.0.0.0

I need to do remote port forwarding that will listen 0.0.0.0 instead of 127.0.0.1 on the remote machine so that I can connect from outside internet to IP_OF_BBB:SOME_PORT in order to connect to SSH port of AAA.

I managed to make this happen by the following:

  1. AAA:~$ ssh -R 22:localhost:2222 user@BBB
  2. BBB:~$ ssh -L 2222:*:2223 user@localhost

Now I can connect to AAA with this command:

ssh user@BBB -p 2223

The local port forwarding is a workaround, of course. Is there any clearer way to do this?

like image 579
ceremcem Avatar asked May 21 '14 11:05

ceremcem


People also ask

How do I forward a remote port?

For remote port forwarding, enter the remote SSH server forwarding port in the Source Port field and in Destination enter the destination host and IP, for example, localhost:3000 . If setting up dynamic forwarding, enter only the local SOCKS port in the Source Port field.

Does SSH support port forwarding?

There are three types of port forwarding with SSH: Local port forwarding: connections from the SSH client are forwarded via the SSH server, then to a destination server. Remote port forwarding: connections from the SSH server are forwarded via the SSH client, then to a destination server.


1 Answers

Enable GatewayPorts in sshd_config (by default it is disabled). Enabling it will instruct sshd to allow remote port forwardings to bind to a non-loopback address. AskUbuntu has a similar question about Reverse Port Tunneling that goes into more details.

like image 100
Linville Avatar answered Sep 19 '22 22:09

Linville