SSH Tunneling to redirect requests from a local port to a remote one


Suppose that you want to access a remote port in a machine that runs a service on port 3306. Also suppose that the remote machine has restricted access to that port only for requests coming from the host “localhost”. You will have to create a tunnel to that machine and tunnel all your requests from you local computer’s port e.g. 2000 to the remote host’s port 3306.

ssh  -L 2000:localhost:3306

After doing this, every request to localhost:2000 will be redirected(tunneled) to the remote machine at port 3306 through a secure channel! The remote machine, will accept all requests coming from the tunnel like if they were coming from localhost.

For me, this was a very nice way to access my MySQL database from my computer with the Sequel Pro client that does not support SOCKS proxies. I tell Sequel to connect to and all the requests that I make, are being redirected to my host ( so that MySQL thinks I am a local user and lets me in.

Let me know if there is something not clear here!

There are 4 comments in this article:

  1. 6/07/2009Mary Florit say:

    cool, i will bookmark it,

  2. 4/10/2009J. Piel say:

    Note that on some distributions the default MySQL install has “skip-networking” in MySQLs config file: my.cnf. If this is the case, SSH tunneling will not work as described above. The fix is to REPLACE the “skip-networking” line with “bind-address =” in my.cnf, and restart MySQL. SSH tunneling should now work as described. MySQL will ONLY be listing on localhost, it will not be exposed to the external Ethernet (unless you have something horribly mis-configured)

  3. 29/12/2009teleskopy astronomiczne say:

    Very nice blog, your article is interesting, i have bookmarked it for future referrence

  4. 29/10/2014credenza 2 inch mahogany say:

    you’re in reality a good webmaster. The site loading
    speed is amazing. It seems that you’re doing any distinctive trick.
    Moreover, The contents are masterwork. you have performed a excellent
    task on this topic!

Write a comment: