Ssh to local network behind a public IP (TCP forwarding)

ip-forwardingport-forwardingssh

I want to connect (using ssh) two remote computers in a local network using a unique public IP X.X.X.X.

               |
HOST_A---------|
  172.1.1.2    |          _____________
               |---------|ROUTER PUBLIC|-----------|INTERNET|-------------|CLIENT
               |         _______________                                      
               |   172.1.1.1       X.X.X.X
HOST_B---------|
     172.1.1.3 |

My public IP has restriction in port 22 so I'm using the port 1234. The router port-forwarding 1234 is enable and directed to HOST_A. Currently, I can access to HOST_B from client executing

$ ssh -p 1234 user@X.X.X.X

Howerver, I can not access to HOST_B and I don't understand how to use -R and -L option of ssh. I read and follow many examples in the web and I can not achieve HOST_B without login in HOST_A previously.

I appreaciate an explanation about TCP-forwarding because I'm not sure about if it is possible to login in HOST_B using the ip X.X.X.X without configuring HOST_A.

An instance of my search:
How to setup ssh tunnel to forward ssh?

Best Answer

I think the better you can do is open 2 ports on router and redirect them; one for host_a like you has done, and other, for example 1235, to host_b. So you can use

ssh -p 1234 user@X.X.X.X for host_a and

ssh -p 1235 user@X.X.X.X for host_b

Related Topic