Port Forwarding
Published on 07 Jun 2004Tags #SSH
The ssh client and server are able to forward local or remote ports through the tunnel and resume delivery on the other side. Port forwardings are either local or remote and are configured on the command line of the client or inside the SSH client configuration:
-
Local port forwarding: Packets to a local port (on the client side) are forwarded through the SSH tunnel and delivered by the ssh server.
-
On the command line:
ssh -L client_port:serverside_host:serverside_port
-
Inside ~/.ssh/config:
LocalForward client_port serverside_host:serverside_port
-
-
Remote port forwarding: Packets to a remote port (on the server side) are forwarded through the SSH tunnel and delivered by the SSH client.
-
On the command line:
ssh -R server_port:clientside_host:clientside_port
-
Inside ~/.ssh/config:
RemoteForward server_port clientside_host:clientside_port
-
Some examples:
-
Forward connections to the local port 80 to the same port on the remote host:
LocalForward 80 localhost:80
Localhost is evaluated on the remote host which resolves to 127.0.0.1 on the remote host.
- Forward connections to the local port 80 to the same port on the host www behind the remote host:
LocalForward 80 www:80
- Forward connections to the local port 80 to the same port on the host www behind the remote host: