Wednesday, November 12, 2008

Reverse SSH Tunneling in Linux


This can be very handy if you want to access a Linux box present inside a NATed Network from a Linux machine outside the network. The hard way is via DNAT using IPTables using Port Forwarding, but this is very, very simple if SSH Tunneling is used.

For example, if you want to access a machine 192.168.1.10 (present under a NAT Network) from another Linux machine having the IP address 202.202.202.202, then here is what you have to do:

1) SSH from the private machine to the public machine using the below command;

ssh -R 18000:localhost:22 remoteuser@202.202.202.202

Here -R specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side. 18000 can be any unused port on the machine.

2) Now from the remote machine, SSH into that machine itself to the port we mentioned earlier.

ssh localuser@localhost -p 18000

That should ask for a password and it needs to be the password of the localuser you have specified in the above command.

0 comments:

 

A Linux Admin's WeBlog! Blak Magik is Designed by productive dreams for smashing magazine Bloggerized by Ipiet The Blog Full of Games © 2008