SSH tunnel to blocked sites while keeping your routes

tl;dr If you can ssh out you can bypass most any network restrictions.

Overzealous IT administrators. Restrictive network policies. Overreaching governmental meddling. What's a humble interweb denizen to do? Short of packing it all in and turning it all off, I say get to know the secure shell, more commonly referred to as ssh. If you've heard of ssh you probably know it can do more than just connect you via an encrypted connection to a remote server. You probably also know that it can forward a local address and port to a remote address and port through your ssh connection using the -L flag.

For example, when I'm on a network that blocks IRC, I use the following command to circumvent it:

ssh -L

Then I connect my IRC client to localhost:6667 which is then forwarded via my ssh connection to Easy peasy. This works because I can control my IRC client and tell it to talk to localhost:6667 instead of What if you have a prebuilt application that needs to dial into a specific website or IP address? You can't control that connection so you intercept it. You can emulate the service IP address locally. Basically you find out the IP address of the service you want to talk to and you tell your computer that it is that IP address by binding it to the local loopback adapter. You know that nifty address? That's your local loopback. The trick is to realize that you aren't limited to that one only. You can add others like so:

sudo ifconfig lo0 add

This tells Mac OSX to add address to the local loopback adapter as if your computer actually was that address. This allows your browser and any other application to operate normally, maintaining all network/vpn applied routes and proxies. The only difference is that this one address will now be smuggled out through the gaping hole your ssh connection made in their network. You need to do this before you establish the ssh connection or else it will error out as ssh will not recognize the address as a local address. Once you've established your local loopback, you can set up your ssh session like so:

ssh -L -L

In this case I'm calling on two specific ports to pass through, 5000 and 5001. 

Here's something I pieced together from a few different posts around the web.