How to tunnel a local port onto a remote server

This is actually pretty easy to accomplish, even though it's somewhat buried in the ssh documentation. Assuming OpenSSH, the basic syntax is as follows:

ssh -R 8080:localhost:80 -N [email protected]

This will open a listening socket on port 8080 of your-server.dyndns.org, and any connections that are made onto your-server.dyndns.org:8080 will be forwarded over the SSH tunnel to the computer which has opened that SSH connection, and from there will be directed to localhost:80.

The -N option instructs SSH not to open a shell or whatever, just to establish the port forwarding, so you can send it into the background and leave it running.

Putty uses pretty much the same syntax, but wrapped into some sort of GUI. The principle is the same though.

But be careful in what you do. Since you're essentially funneling external traffic into your network, you are pushing a hole in your network's firewall. If it is not your network, your admin may object to this and take you responsible—usually there is a reason why you are not allowed certain kinds of traffic.


To by able to forwarded your local port 80 not only to the loopback interface (127.0.0.1) you have to configure GatewayPorts clientspecified in /etc/ssh/sshd_config on the remote machine first.

Then forward your port with:

ssh -R 0.0.0.0:8080:localhost:80 -N [email protected]