These days VPNs are really popular and people are using them for various reasons. You probably are using one every day in order to access your company platforms and infrastructure if you're working from home. However, people use VPNs for many other reasons - to browse through the internet securely, to change their IP and location in order to access sites or applications that are restricted to certain IPs or geo-location or you can use a VPN in order to access your home network and connect to your home devices whenever you're away from home for a vacation and so on.
If you want to access your home network in order to browse the internet when you're using public networks then this guide is for you!
I've tried a few VPNs on my Raspberries but I'm really impressed by the PiVPN project because it's simple and fast to install and configure.
I recently had issues with my SD Card and I needed to re-install the Raspbian OS on a new SD card and configure everything I had from scratch and thanks to the PiVPN I spent less than 15 minutes in order to have my VPN configured.
I will recommend you to check the About page on the PiVPN website if you want to learn more about the project:
Since this is a Raspberry Pi tutorial you should have a Raspberry Pi in order to use it. You can run the PiVPN on Raspberry Pi OS (I currently using it on my RasPi OS Buster) but this should work fine on Ubuntu Desktop or similar OS on your Raspberry Pi.
The installation script uses
curlso you should have it installed as well.
The installation is pretty simple. You just run the official install script and then you will be prompted with a dialogue box and will be asked a few questions on setting up the OpenVPN server. I'm using the default settings and everything works just fine, but you're free to choose a different configuration if you wish to do so.
Note! At the end of the installation process, you will be asked to reboot the Raspberry PI in order to complete the process, so please make sure to save any open files or projects before you start the install script.
The install script:
curl -L https://install.pivpn.io | bash
During the process, you can choose whether to use WireGuard or OpenVPN. If you're planning to use it on mobile devices WireGuard is recommended although I'm using the OpenVPN option and still use it on my phone. After selecting any of them you will be asked if you want to customize the default settings. If you want to use the default settings just choose "No"
You can also modify the default OpenVPN port. If you don't need to use a custom port for it just hit enter and the default port 1194 will be used.
For the DNS provider, you will be presented with several options. The default selected is to use CloudFlare but if you use a local DNS resolver you can choose PiVPN-is-local-DNS or to use your own select custom.
For the Unattended upgrades, I will recommend selecting "Yes" so security patches can be applied.
At the end of the installation process, you will be asked to reboot the Raspberry PI in order to complete the process.
Once your Rasberry is up and running you can open the terminal and check if OpenVPN is up and running.
sudo service openvpn status
You should see a similar output if everything went well.
In order to access this server remotely, you will not set up Port Forwarding. This is needed because the OpenVPN port is not open to connections from external networks. The process will be different on each router model. I will recommend you to check your router model and search on how to port forward on that specific router. The process should be explained on the manufacturer website or you can also use instructions from the manufacturer forum.
If you're having issues to complete the Port Forwarding step, feel free to DM me and I will try to guide you through the process.
In order to add a new client open the terminal and run the following command:
If you want to check the available options with the cli you can use -h or --help:
When client profiles are created, they are saved in /home/$USER/ovpns
You need to load the .ovpn file on the client device in order to access your server. You can either copy the file to the device or if you're going to use it on your mobile device you can also email the file (not recommended due to security concerns) and open it from the mobile device or store the file to secure file storage!
OpenVPN Connect is the recommended software to use on all iOS, Android, macOS, Linux and Windows devices. You can download it from HERE and for mobile devices, you can download it from App Store and Play Store.
If everything went well you know have an OpenVPN server up and running on your Raspberry Pi. You can use it to access a device on your home network (I often use it to control my smart lights) and to securely browse the internet when you're outside your home.
If you've enjoyed reading this post or learned something new and would like to support me to publish more content like this one you can support me with buying me a coffee: