Connect with us

Raspberry Pi

How to Setup Your Raspberry Pi as a VPN Router?



Raspberry Pi VPN Router

Raspberry Pi VPN Router: To create a VPN Router through the Raspberry Pi, the built-in WiFi, the newest version of the Raspberry Pi is very useful than ever for the networking projects. You can use the Raspberry Pi as the VPN Access Point, which enables you to browse the web more privately.

Raspberry Pi VPN Router
Raspberry Pi VPN Router

Raspberry Pi: How to Compile VLC Media Player with Hardware Acceleration for Raspberry Pi?

How to Setup Your Raspberry Pi as a VPN router? | Raspberry Pi VPN Router

Step 1: The first thing you have to do is to Turn your Pi into a wireless access point

Step 2: Now install the OpenVPN, to set up the VPN. Open the command line and type this to get it:

sudo apt-get install openvpn -y

Now just reboot the Raspberry Pi:

sudo reboot

Raspberry Pi VPN Router
Raspberry Pi VPN Router

Step 3: Download and unzip VyprVPN, You will need one more program for this project, and that is VyprVPN. You can get it through the command line:

cd /etc/openvpn

This put you in the right directory.

sudo wget

This command downloads the file.

sudo unzip

The above command unzips the file.

Step 4: List the VPNs, Enter into the new directory here, then type ls to list files. We are using the 256-bit version so that our path reflects that.

cd GF_OpenVPN_10142016/OpenVPN256

You can see a whole bunch of files which ends in .ovpn. These are the different VPNs you can use, listed by location. Just remember these for when you want to connect to the specific VPNs. You can write them down, or just run these commands again when you forget.

Step 5: Now create the authorization file you have to be authorized to use the VyprVPN. Now create the authorization file:

sudo nano /etc/openvpn/auth.txt

Raspberry Pi VPN Router
Raspberry Pi VPN Router

The above command will create a new file. In the file, type two lines. The first will be your username, the second is your password. This will be your VyprVPN login (if you don’t have the VyprVPN account, Just create one). Now get out of the file (Ctrl+X), save it (Y), and confirm (Enter).

Related: How to Set up a Raspberry Pi AirPlay Receiver?

Step 6: Then run a test

sudo openvpn –config “/etc/openvpn/GF_OpenVPN_10142016/OpenVPN256/FILENAME.ovpn” –auth-user-pass /etc/openvpn/auth.txt

Remember the VPN you wish to use. Plug that in where you have the FILENAME.ovpn. If you did it correctly, you will get a bunch of text that includes happy words “Initialization Sequence Completed.”

Step 7: You are not done yet. You changed a bunch of stuff in the iptables when you used the Raspberry Pi as a wireless access point, but you need to change that now.

sudo iptables -F
sudo iptables -t nat -F
sudo iptables -X

This clears out the old stuff.

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

And this is what you need now. This will route your wlan0 connection through the tunnel instead of over the Ethernet connection.

sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

This saves your work.

Step 8: Make things automatic, Let’s set it up so that your VPN starts up when the Raspberry Pi starts up. Now you need to edit the rc.local file.

sudo nano /etc/rc.local

In that file, look for the line which says “exit 0” and add these lines just above it:

sleep 5
sudo openvpn –config “/etc/openvpn/GF_OpenVPN_10142016/OpenVPN256/FILENAME.ovpn” –auth-user-pass /etc/openvpn/auth.txt

Related: How to Create A Raspberry Pi Clock Using the Sense HAT?

In the last time, the FILENAME.ovpn was your choice from step 4. Head out of here with same keystrokes as your last file editing step: Ctrl+X, Y, Enter. That’s it! Everything should work properly now. You can check to make sure that everything starts with each boot by rebooting the Pi with sudo reboot.

Thus Raspberry Pi VPN Router will work correctly. Thank you for reading this post.