HTTP forwarding through multiple gateways

Tags:

In my little writeup about SSH tunneling I have provided an introduction to using the SSH local and remote port forwarding features, with an emphasis on remote port forwarding useful for X tunneling. Here's a complete example of local port forwarding, useful for tunneling HTTP through multiple gateways.

Assume that I have the hosts red, blue and black just as in the aforementioned article, and there is a super secret HTTP service running at black:8080 that I want to access from home. In this case I have to establish a tunnel with local forwarding, since HTTP requests will originate from my machine. Let's say I want to use port 8099 for the tunnel. Here's what to do:

home> ssh -C -L 8099:localhost:8099 tom@red
Password: ********
red> ssh -C -L 8099:localhost:8099 tom@blue
Password: ********
blue> ssh -C -L 8099:localhost:8080 tom@black
Password: ********
black>

... and, in my locally running browser, connect to http://localhost:8099 which is the local end of the tunnel. This will allow me to access the HTTP service that is running behind multiple layers of gateways (presumably firewalls that I somehow have access to, but that's not the point).

It should now be clear that SSH tunneling is the single best thing since sliced bread.