Skip to content

Server notes

SSH port forwarding in a nutshell

See an intranet site from home by forwarding a local port through an SSH connection. The syntax is short; the port choice needs care.

By Jozsef 2 min read

My goal was simple: I wanted to see an intranet website from home with my Linux laptop. I could connect to the intranet web server over SSH, but I wanted the page in a browser.

The solution is SSH port forwarding. From the laptop, the syntax is:

bash
ssh -L <myPortNumber>:<RemoteIP>:<RemotePort> <host> [other ssh options]

My working command looked like this:

bash
ssh -L 8088:127.0.0.1:80 intranetserver.example.com

Now I can open http://localhost:8088/ in a browser and view the intranet.

Choosing the local port

The first number is the port on your machine. Use a value above 1024 unless you are root. Check what is already in use:

bash
netstat -ltn --prog

Do not choose a port from that list. It is already in use by another application.

When the tunnel closes

The forward lasts for the life of the SSH session. If the page stops loading, check the terminal first. A dropped session is the usual cause.

Sources and further reading