Ssh – Tunnel HTTP traffic over ssh

ssh-tunneling

Here's my setup. I have a private network with one public IPv4 address. On this private network, I have two servers, 192.168.1.10 and 192.168.1.20. .10 is my ssh bastion host. I have set up port forwarding so that I can ssh to this server from the internet. I have also set up my ssh config on my workstation so that I can ssh to 192.168.1.20 from the internet as well, via 192.168.1.10. Workstation is not on the private network, it is a machine on the internet.

Here is my goal: I want to be able to connect to an http service on 192.168.1.20 via internet, from my workstation, (just by hitting localhost:8080 or similar) but tunneled over ssh. What tunnel(s) do I need to set up, and on what machines?

Thanks!

Best Answer

From your workstation set up tunneling via:

ssh -L8080:192.168.1.20:80 server10

Where "server10" is the public name you use to reach 192.168.1.10.

This will listen locally on port 8080 and forward any data to 192.168.1.20:80 from the target host.

An alternative is using the -D option for ssh for setting up a socks proxy. This will allow you to reach each port on each host, but you have to configure your application to use that proxy.

Related Question