domingo, 22 de mayo de 2011

Using SSH tunnels

SSH tunneling (also known as SSH port forwarding) is a very useful technique when you need to access for example to an Oracle database, but you only have access via SSH to another host in the same network.

In this example,we will use the common SSH client named PuTTY. Suppose we have SSH access to machine 10.140.1.231, but we want to connect to an Oracle database running on port 1521 of machine 10.140.1.230.

The first step is to create a new session (or reuse an existing one). In this example, we will use a session named 'mordor' to connect to a host with IP 10.140.1.231 using the standard port of SSH (22):



Next step is to create a new SSH port forward. This is done in the menu 'Connection > SSH > Tunnels'. In this example, we will define a local port (in this case 1521) and a remote port (10.140.1.230:1521):


Once this is done, next step is to open the SSH connection to 10.140.1.231. As usual the terminal will ask us user and password. Once we have logged on, a local port in our computer will be defined, in this case port number 1521.

How to connect to the database ? Just start your favorite SQL client (TOAD, Squirrel, etc) and define a connection with an URL like this (note the use of 'localhost'):

jdbc:oracle:thin:@localhost:1521:MYDATABASE

The SQL client will connect to port 1521 in your computer, but PuTTY will automatically redirect the traffic to 10.140.1.230:1521 .

1 comentario:

Francisco Ferri Pérez dijo...

Hola Jose Ramón, solo añadir que para mac hay una aplicación que va muy bien para simplificar la creación, activación y desactivación de los túneles ssh: https://itunes.apple.com/es/app/ssh-tunnel-manager/id424470626?mt=12