5

I have a remote server that only exposes SSH. It has services running on other ports, for example a database on port 3306. These ports cannot be accessed remotely, but are accessible from within the server context (localhost:3306).

Using ssh -L I can access a single port on the remote server. But how can I make all these ports accessible to my local machine over an ssh/sshuttle connection?

1
  • Of course, you can add as many -L LOCALPORT:REMOTEIP:REMOTEPORT options as ports you need to the same ssh command; it isn't limited to only one, but the sshuttle mechanism is easier.
    – Fjor
    Oct 4, 2020 at 2:21

1 Answer 1

5

On the remote server define a secondary IP address, for example 10.0.0.1, that points to itself. (The same way 127.0.0.1 does.)

On your local machine, create your sshuttle connection as follows:

sshuttle -r user@remote 10.0.0.1
# "user" is your username on the remote machine
# "remote" is the name or IP address of the remote machine

You can now access the remote server at the 10.0.0.1 address. Because it understands connections from 10.0.0.1 to be "itself", all the ports are accessible at that address. (They stop being accessible as soon as you close the sshuttle connection.)

You can confirm this with the following commands:

nmap remote # returns only ssh port
nmap 10.0.0.1 # returns all ports

You can now connect to your database with the address 10.0.0.1:3306. For example, if it's a MySQL database you can connect to it uing MySQL Workbench.

If this approach suits you, you may want to investigate using sshoot to manage your sshuttle connections.

2
  • "user" is your user on the remote machine and "remote" the IP or name of the remote server? And this allows you to connect with (for instance) workbench to the remote server?
    – Rinzwind
    Jul 13, 2017 at 15:13
  • @Rinzwind yes! I've updated the answer to clarify
    – lofidevops
    Jul 14, 2017 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .