Weekend Project: Part 2 – Configuring a VPN on a Raspberry Pi

Following on from my previous post I will be setting up a VPN on my Raspberry Pi with an aim to better protect my online privacy with a VPN and Pi-hole. Having this setup will allow me to connect various household devices to the Raspberry Pi which will then pass traffic though the VPN. To allow connections we must make sure the Pi has a static IP address.

To set a static IP address we must add the address we want to the /etc/network/interfaces file on the Pi.

Add the address you wish your Pi to have in my case I chose 192.168.1.123 for gateway specify your gateway normally this is the address you us to access your router.

auto eth0
iface eth0 inet static
address 192.168.1.123
netmask 255.255.255.0
gateway 192.168.1.254

Lets start getting the packages we will need to configure our VPN by running the below;

paz@raspberrypi:~ $ sudo apt install openvpn curl iptables-persistent python-requests -y

Next we will begin configuring the VPN. For my VPN provider I use PrivateVPN. They are well respeceted, reasnably priced and keep no logs what so ever.

Download PrivateVPN’s openvpn files to your Raspberry Pi with the below commands;

paz@raspberrypi:/etc/openvpn $ sudo wget https://privatevpn.com/client/install.sh
paz@raspberrypi:/etc/openvpn $ sudo su -
root@raspberrypi:~# cd /etc/openvpn
root@raspberrypi:/etc/openvpn# ./install.sh

Running install.sh prompts you for username/password and creates the a VPN connection on your Pi that can be used on your Pi.

Edit the file /etc/openvpn/privatvpn.conf with the details of the PrivateVPN exist point you wish to connect to PrivateVPN provides a script to allow you to start the VPN called privatvpn. After install this file is located at /usr/bin/privatvpn. Add this file location to /etc/rc.local which will ensure that the VPN starts on startup should your Pi reboot or require a restart.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.