Home    | Software    | Articles    | Tips'n Tricks    | Contacts    | Support Us  
Home arrow Tips'n Tricks arrow Linux arrow Tunneling Postgres/Mysql

Tunneling Postgres/Mysql

The methods exposed here are valid for almost all network services, but here we'll see specifically how to access Postgres or Mysql located behind a firewall.
Under *nix systems we can just make use of ssh from the command line. Supposing that the firewall IP is X.X.X.X , that we have an ssh account on it(with username = user, i.e), and that our database server behind it has IP Y.Y.Y.Y , for tunneling postgres, from the command line we'll type:

ssh This e-mail address is being protected from spam bots, you need JavaScript enabled to view it -L 5432:Y.Y.Y.Y:5432

We're instructing ssh to :
1) connect to X.X.X.X using username "user"
2) Forward calls to localhost(127.0.0.1), port 5432 to host Y.Y.Y.Y(located behind the firewall) port 5432
For mysql is the exact same thing, but the port will be 3306.
Note that if on our localhost we already have a postgres or a mysql, we must use a local unused port instead. For example, in case of an existing mysql installation, if port 4306 on localhost is free we could type:

ssh This e-mail address is being protected from spam bots, you need JavaScript enabled to view it -L 4306:Y.Y.Y.Y:3306

Just to be clearer, in the "-L" clause the first port is the one mapped on localhost, the second is the remote one.
Ok, now we need to connect to the tunneled database. On the db connection url, we will use 127.0.0.1 as host and our local port (4306 in our last example).

Another option, system independent, is Tunnel4J, a little free java GUI that allows to create connections on remote servers and do ports forwarding for tunneling purposes.
 
< Prev   Next >

  Articles RSS feed

Latest Articles
Latest Software
   
designed by allmambo.com