rameezk
rameezk

Reputation: 353

Access a service on a specific port using SSH Tunnels

I have the following scenario:

I need to access a service on a machine (port 9999) from outside the network using ssh tunneling. The IP address of the machine is 10.0.0.7. I have access to a VM (IP: 10.0.0.3), which I can access from outside the network using ssh on port 22.

How can I access the service (that's running on port 9999 on 10.0.0.7) from my home network?

I have tried reverse forwarding the port but no luck.

Also, we have a few of these polling machines on the network that all run on port 9999 (IP's ranging from 10.0.0.6 to 10.0.0.15). Is a possible to access all of them as well?

Thanks for the help!

Upvotes: 0

Views: 520

Answers (1)

Ben
Ben

Reputation: 6767

Using SSH's standard tunnelling should work:

ssh -L9999:10.0.0.7:9999 10.0.0.3

You should then be able to connect to localhost:9999 and that will be equivalent to connecting to 10.0.0.7:9999. If you want to do this for lots of hosts, you can do lots of -L statements, but the first port has to be unique:

ssh -L9999:10.0.0.7:9999 -L9998:10.0.0.8:9999 10.0.0.3

Then you have localhost:9999 and localhost:9998. To speed this up, you can add the following to your .ssh/config file:

Host 10.0.0.3
    LocalForward 9999 10.0.0.7:9999
    LocalForward 9998 10.0.0.8:9999
    LocalForward 9997 10.0.0.9:9999
    LocalForward 9996 10.0.0.10:9999
    LocalForward 9995 10.0.0.11:9999
    LocalForward 9994 10.0.0.12:9999
    LocalForward 9993 10.0.0.13:9999

Then ssh 10.0.0.3 will automatically set up those tunnels for you.

Upvotes: 1

Related Questions