There would be instances where in we do not have direct access to Database server running in an external network, i.e we cannot open connection to the database directly from our local machine .Usually to access these databases we will have to login to another server(Bastion host) thru putty to get access to Database.But what if I want to access the Database instance using a GUI tool like sql developer?
This is where ssh tunneling(also known as port forwarding) would come in handy.
What is Tunneling?
Tunneling allows a network user to access or provide a network service that the underlying network does not support or provide directly.
A tunnel is exactly as the name suggests, a tunnel over SSH on which we’ll forward a specific port. The port will be accessible on your local machine, but will be automatically forwarded to the remote machine so it appears as if you’re remote service (MySQL in this case) is actually local. This doesn’t just have to work with MySQL, it can be used for any TCP based service, such as HTTP on port 80.
How to set up tunneling in putty?
- In putty create a session for the server which has access to MySql Server
- Add tunneling information by clicking on Tunnels under Connection=>SSH=>Tunnels
Source port Field: Key in the port on which you want to access the mysql server from localhost(I chose 9999 port).
Destination Field: Key in the IPAddress of the mysql server with the port Eg :10.20.30.40:3306
Click on Add button
- Click on Session(left top) and save.Then open the session.
- Now login to the box using putty with appropriate credentials.To connect to the remote mysql server using SQLDeveloper(or any other similar software) we should connect to