[Gllug] Iptables routing via SSH tunnel

Alain Williams addw at phcomp.co.uk
Wed Apr 18 11:19:18 UTC 2012

On Wed, Apr 18, 2012 at 01:19:25AM +0100, Vipul Agarwal wrote:
> Hi guys,
> I have two linux servers with root access and an external database server
> which is managed by someone else.
> Initially, only one of my server can access this external database server
> while the other can't due to IP restriction.
> I want to enable access to this external database server to my other linux
> server temporarily as it'll take few days to get the IP added to the
> firewall.
> I think this can be done using a SSH tunnel. Please help me writing the
> correct iptables rules to route all the traffic to a specific IP/port via
> the SSH tunnel.

If this is for a couple of days you may be able to do it via ssh.
Reconfigure the database client to connect to localhost. If the server that you
are connecting to is mysql it will listen on port 3306.

On the client machine run:

    ssh -L 3306:0:3306 database_server_machine

ssh will carry (forward/tunnel) requests on the client machine port 3306 to port
3306 on the server.

A hack - but might be easier for a couple of days.

Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>
Gllug mailing list  -  Gllug at gllug.org.uk

More information about the GLLUG mailing list