This is a really useful technique I recently discovered which allows you to bind a port on your local machine to the local port on a remote machine. Why would you want to do this?
Well in my case I was working on a remote web server via ssh, setting up some web aplications on various different ports. The hosting company had yet to open these ports to the outside world. However, this technique allowed me to bind the local ports on the remote machine (running the web applications) to my local machine. This allowed me to test and configure each application as if it was installed on my local machine, simply by accessing localhost:xx in my browser. The port numbers don’t even have to match! I ended up binding remote port 8080 to port 80 on my local machine.
This can be achieved by issuing the following command on the local machine…
ssh $REMOTE_IP -L $REMOTE_PORT:localhost:$LOCAL_PORT
Example binding remote 8080 to local 80:
ssh myhost.com -L 8080:localhost:80