SSH port forwarding
Local port forwarding
Section titled “Local port forwarding”Assume you are on the client computer and want to ssh into server.example.com
$ ssh -L 10080:foo.example.com:80 server.example.comOnce you have connected, leave the ssh login window running.
At this point, on client, there is a port open on localhost:10080
If you access it, it will connect to foo.example.com from server.example.com.
Instead of binding to localhost on the client, you can specify the interface or listen to all using * e.g.
$ ssh -L '*:10080foo.example.com:80' server.example.comRemote port forwarding
Section titled “Remote port forwarding”Assume you are on the client computer and will ssh into server.example.com.
$ ssh -R 10080:foo.example.com:80 server.example.comOnce you have connected, leave the ssh login window running.
At this point, on the server, there is a port open on localhost:10080
If you access it (from the server), it will connect to foo.example.com, from the client.
Instead of binding to localhost on the server, you can specify the interface or listen to all using * e.g.
client$ ssh -R '*:10080:foo.example.com:80' server.example.comSpecifying the interface only works if the GatewayPorts option is enabled.