15 Jun 2008

Creating an SSH Tunnel

Sometimes we just needed to map an ethernet port on my machine to a remote server, in order to access it as it was locally available through 120.0.0.1.

This is the kind of situation in which I use an SSH tunnel.

Assuming that you want to access a database server running on port 3306 on a machine whose IP address is 192.168.1.120 and you don't have access to that machine but can log into 192.168.0.10 from which you can then connect to the database server machine.
Then you could do this:

# ssh -L <localport>:192.168.1.120:3306 -l <remote-username> 192.168.0.10

After a successful login you would be able to connect to the remote database server in your local machine on the port you specified.

# mysql -u DB_USERNAME -h 127.0.0.1:<localport>

No comments: