How to forward local ports using SSH

If you are using SSH to connect to a system and then want easy access to a port on another system that is behind it, then you can use the local port forwarding option in OpenSSH.

The command syntax is as follows:

ssh -L 8080:internal.example.com:80 myserver.example.com

This will forward connections make to your local port 8080 to the internal.example.com server on port 80, which in this example is behind the server that we have SSH'ed into (myserver.example.com).

You will need to stay connected to the server in order keep the port forwarding working.

PuTTy in Windows also has this feature.

Last updated: 28/11/2007