Use a ssh tunnel to create a simple VPN in OSX to watch country-blocked streaming — via script.

May 16th 2016
Author profile picture

@rubasDominic Rubas

Sometimes you are at the wrong time at the wrong place.

There is no need for a fancy VPN server when you have access to a ssh server. This could be a machine back at home, a small vps server or even a shared webhosting account.

Tip: Run your own ssh server at port 443 to circumvent any corporate firewall restrictions.

Use SSH Tunnel as a poor man's vpn

ssh -D creates a local SOCKS proxy and forwards all your traffic on this port through the ssh connection.

It is super simple!

$ ssh -D 8000

There is now a SOCKS proxy running under localhost:8000.

Setup a SOCKS proxy in OSX via Terminal

Now you have to configure your network settings to use this SOCKS proxy. Of course we want to automate this for our script.

$ sudo networksetup -setsocksfirewallproxy "Wi-Fi" localhost 8000

Finally we pack everything an a nice script

$ ./ { start | stop }

The end.

Be aware!

Your terminal commands will not use this SOCKS proxy by default. For some (wget, curl..) there is a configuration flag to use a proxy.

But if you want to tunnel all your traffic, you should have a look at sshuttle.

But for me using sshuttle was significantly slower than a simple ssh tunnel. If you run into this problem, try to run sshuttle with the option `--no-latency-control`.



The Noonification banner

Subscribe to get your daily round-up of top tech stories!