Hello everyone. Today I want to show you how you can use your Raspberry Pi to tunnel all your traffic over a VPN connection. (I for example use this solution to watch my favorite TV shows on hulu. (I´m not an American and hulu is blocked outside the USA as you may know)). Ok let´s go.
The first thing you need to do is go to the VPNGate website and search for a VPN server. (one in the United States of America if you want to watch videos on hulu if you are located outside of the United States of America). If you found a VPN server download the ovpn file (OpenVPN) and store it on your Raspberry Pi.
Before we start you need to setup your Raspberry Pi as a Wireless Router like I explained in this post. After this is done we continue with the following:
To prevent issues update your Raspberry Pi first:
sudo apt-get update sudo apt-get upgrade
Next install OpenVPN:
sudo apt-get install openvpn
Now move the ovpn file you downloaded by running the following command:
sudo mv <ovpn file> /etc/openvpn/openvpn.conf
Next we need to create a text file containing the user and password credentials:
sudo nano /etc/openvpn/user.txt
For a VPNGate VPN server enter vpn as username and vpn as password. Save the data in user.txt:
Next adjust the permissions of your user.txt file by running:
sudo chmod 755 /etc/openvpn/user.txt
Next we need to edit the openvpn.conf file (the ovpn file we downloaded earlier):
sudo nano /etc/openvpn/openvpn.conf
Now search for the following line:
And replace it with this line to tell OpenVPN to use the user credentials provided in the user.txt file:
Now adjust the permissions of the openvpn.conf file by running:
sudo chmod 755 /etc/openvpn/openvpn.conf
Next reboot the Raspberry Pi. (It is faster than restarting the necessary services manually.)
If you now have a look at your interfaces after your Raspberry Pi is has finished rebooting by running:
You will notice that you have a new interface called tun0. This is your new VPN tunnel interface.
If you followed my instructions from this post we need to do some clean up. Run the below command to clean up the iptables configuration:
sudo rm /etc/iptables.ipv4.nat
Next run the below commands to redirect all your traffic through the VPN tunnel interface:
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE sudo iptables -A FORWARD -i tun0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o tun0 -j ACCEPT
Save the iptables configuration by running:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Now reboot your Raspberry Pi one last time:
If you now connect to your Raspberry Pi´s wireless network all your traffic will be redirected through the VPN tunnel interface. (You can check if it works by using this website.)
Here is a picture from hulu without using this solution: (outside of the USA of course)
And here is a picture of hulu while using this solution:
That´s it. It´s as simple as that. I hope you liked my post and I hope to see you again next time 🙂
And as always you can download all relevant files I used from here.
Update: Please keep in mind that the VPN relays on VPNGate are run by volunteers and that this means that your experience and the quality may vary. Please keep also in mind that hulu tries to blacklist all kinds of VPNs to make solutions like this useless so this solution might not work anymore in the future.