Saturday, March 27, 2010

SSH Port Forwarding Example

Like everyone, it takes me a few tries before I get a port forwarding command line right. Here is yet another example for everyone, just in case you happen to have this specific example.

Lets say you want to get to your database, but it isn't exposed:

You want to forward some port on DMZ to the DB. Lets say it is Oracle running on 1521. Then, from the DMZ host you should issue the following command:

ssh -g -L 5000:DB_HOST:1521 boneill@DB_HOST

At this point, you should be able to connect to DMZ:5000 as if it were DB:1521.

REALLY REALLY IMPORTANT is the "-g", that allows remote connections to 5000. Otherwise, it will just bind to the local interface and you won't be able to connect from CLIENT.


jlorenzen said...

How do you do this on windows? :)

Peter said...

If you have Putty, it is real simple to set up, look at Category / Connection / SSH / Tunnels (and be sure to check the checkbox for accepting remote connections)

ryran said...

While I'm sure this worked for the OP, it's worth noting that the example would be more complete if the command were:

ssh -g -L 5000:localhost:1521 boneill@DB_HOST

The second item in the listed arguments to -L is the hostname as resolved by the remote ssh host -- i.e., the hostname as resolved by DB_HOST.

It's important to understand this because the ssh host might not be able to resolve itself by the name the local system knows it as.

peterjohn said...

Pretty good post. I just came across your site and wanted to say that I’ve really enjoyed reading your posts. In any case I’ll be subscribing to your feed and I hope you will keep a good work!Cheer!

sap online training
software online training
sap sd online training
hadoop online training

peterjohn said...

I appreciate you sharing this article. Really thank you! Much obliged.
This is one awesome blog article. Much thanks again.

oracle online training
sap fico online training
dotnet online training

Anna said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Course in Chennai

Java Online Training India