Reverse Tunneling and mysql
Recently, I needed my app in staging to use my local database. Since staging server was on a different network that didn’t have access to my local machine (DMZ), I had to use ssh tunnelling. Here is how I did it:
I setup reverse tunnel that allowed mysql connection from staging server to my local database:
ssh -R 33306:localhost:3306 staging_server
This setup reverse ssh tunnel that allowed anybody trying to connecting to msyql server on staging_server at port 33306 to be routed to mysql server running on my local machine on default port (3306).
With this, I was able to do following on remote server:
mysql -h 127.0.0.1 -P 33306 -u root -p
This comment is trying to connect to mysql on port 33306 on localhost which is getting tunneled to mysql server on my local machine. In the above command, “-h 127.0.0.1″ is required since otherwise mysql will try to connect to “localhost” using /tmp/mysql.sock (socket connection). Also, firewall on staging_server prevented any incoming connection for port 33306, so I couldn’t use “-h 192.168.84.70″ which was the real IP of staging server. Instead, I had to use 127.0.0.1.
Nothing earth-shaking, just a few quirks when getting reverse tunnelling to work.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.





