0

Let's say there are three computers, A, B and C.

Computer A needs to connect to computer C on port 9103.

However it is not able to reach C. But it can reach computer B, which can reach computer C.

I know that this can be done with ssh tunnels. However what makes this complicated is that computer A can't ssh into computer B because of a firewall, but B can ssh into computer A. So a reverse SSH tunnel can be created from B so that A can reach B.

Is there a way that a tunnel can be created on computer B so that computer A can reach computer C by going through computer B?

  • localhost:9103 on C or eth0:9103? Can you open any ports on B? Must the connection from A to C be secured by SSH or is connectivity enough? – Hauke Laging Apr 16 '18 at 22:02
1

On B, create a reverse tunnel from A:59103. The endpoint relative to B is C:9103.

ssh -R 59103:C:9103 A

Change the port number on A from its 59103 to something that suits.

This solution takes your statement that B can reach C at face value. The connection from B to C is not secured with ssh.

0

If you want to be slightly fancy, you can establish an nc tunnel on demand instead (if nc is installed on B), with something like the following (from host A):

$ ssh C -oProxyCommand='ssh -q B nc C 9103'

That proxy command means to ssh to B and run nc connecting to port 9103 on C as tunneling for the ssh connection from A.

If it's something you'd always do, you should put it into~/.ssh/config on host A, with the following:

host C
    ProxyCommand ssh -q B nc C 9103

Then the command line is simply:

$ ssh C

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.