How To: Tunnel Connections Over SSH

Uncategorized 2 Comments »

I’ve been doing some work involving an application that needs to query databases on separate servers however one of the servers will only accept mysql connections locally so the way round it is to forward connections from a port on one system to a port on a remote system. That way the connection to the remote database will appear as though it originated locally and be accepted.

To set up a tunneled connection you issue the following command on any client:

ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com

The first command tells ssh to log in to remotehost.com as myuser, go into the background (-f) and not execute any remote command (-N), and set up port-forwarding (-L localport:localhost:remoteport ). In this case, we forward port 3307 on localhost to port 3306 on remotehost.com.

WP Theme & Icons by N.Design Studio | Akismet has gobbled 339,509 spam comments...Mmmm Tasty :-)
Entries RSS Comments RSS Log in