Thursday, October 14, 2010

Connect to a port of a remote server through SSH (local port forwarding)

This is the scenario

You want to connect to a remote server's webserver (port 80), but you only have permission to SSH to that server. Do the following:

ssh -L 8080:localhost:80 remote_server

Now you can point your browser to hhtp://localhost:8080 and view remote server's port 80

localhost is relevant to the remote_server

Also, you can do

ssh -L 8080:remote_server_2:80 remote_server_1

Now if you point your browser to http://localhost:8080 you will connect remote_server_2 port 80. The connection will go through remote_server_1 and remote_server_2 will identify remote_server_1 as the source of the request.

This way you can view a web server of a system even though you cannot connect to it directly. Of course remote_server_1 must be able to connect to remote_server_2 at port 80.

You can also use Putty to enable port forwarding. Go to Connection-->SSh-->Tunnels and set the required options.

No comments:

Post a Comment