How to open port via SSH tunnel?
Solution 1:
(Note: Jakuje answered while I was composing my answer. It's more elaborate from the start, so I'm posting it anyway.)
If I get you right, all you need is to forward a local port through SSH. I assume you have SSH access to B
.
Linux command to run on A
:
ssh -NL 2345:127.0.0.1:80 B
Now you can connect to the port 2345
on A
and it should be equivalent to connecting to the 80
port on B
from the B
itself.
Few remarks:
-
-N
causesssh
not to execute a command on the remote (B
) side; perfect for port forwarding. - The number
2345
is arbitrarily chosen; it may be any number from1024
to65535
(binding to a port lower than1024
requires root access usually). If you happen to hit the already occupied port, then try another number. - The
127.0.0.1
address I used requires your web server onB
to listen on theloopback
interface. If it listens on some other address(es) only, use it instead. This address should be a valid address of your server as seen from within the systemB
. It doesn't matter at all what this address means toA
nor if it means something in the first place. - If you need computer
C
to connect to the2345
forwarded port onA
then you should get familiar withssh -g
option. Readman ssh
.
Solution 2:
Use local port forwarding:
ssh -L 80:localhost:80 B
and then connect to localhost:80
. The connection will be forwarded to the B
's port 80