For a deeper visual explanation, see A Visual Guide to SSH Tunnels: Local and Remote Port Forwarding.
Local Tunneling to a Server
Local tunneling (local port forwarding) lets you tunnel traffic from your local machine to a remote host through an SSH connection. Use the-L flag and provide:
- A local port to listen on
- The remote host IP or hostname to forward to
- The remote port to forward to
localhost:8080 in your browser or with curl will serve the content hosted at 10.0.0.12:80 on the remote network.
Parameters
| Parameter | Description |
|---|---|
-f | Send SSH to the background before executing |
-N | Do not open a shell or execute a program on the remote side |
-L | Establish a local tunnel to the remote server |
Terminating a Background Tunnel
If you used-f to background the SSH process, find and kill it by PID:
Local Tunneling — Local Network
You can tunnel a service running on the remote host’s local network to your local machine.localhost:8080 on the remote server to localhost:8080 on your local machine.