Creating your own VPN on a Raspberry Pi is a relatively straightforward process, involving numerous steps. We've put together a short guide that'll walk you through installing an OS, setting up the VPN, creating users, and logging in using your favorite client.
Products used in this guide
- The Pi itself: Raspberry Pi 4 (opens in new tab) ($66 at Amazon)
- MicroSD card: Samsung EVO 32GB MicroSD (opens in new tab) ($14 at Amazon)
How to build your own VPN with Raspberry Pi
Configuring your own VPN is a great way to save a little on a monthly subscription while getting to know the ins and outs of how it all works by setting it all up. This route does come with some risks, however. Since this server will be running on your home network and will be accessible from outside, you'll need to make sure everything on your LAN is secure.
Installing the Raspbian OS
- Download Raspbian OS ISO.
- Write the ISO file to your SD card, using an app like Rufus.
- Insert the SD card into the Raspberry Pi.
- Plug in your favorite keyboard and mouse.
- Follow the installation wizard.
- Upon completion, ensure the OS is secured with a password.
- We'll also need to set a static IP for the VPN server to use. Edit
/etc/dhcpcd.confand set static ip_address to one not used by any other device on the network. Here's an example of what may be present:
- interface eth0
- static ip_address=192.168.1.30/24
- static routers=192.168.1.1
- static domain_name_servers=192.168.1.1
- Save the file.
- If you have a static external IP from your ISP you can move onto installing the VPN, but if your ISP provides a dynamic IP address (as in it changes every now and then to a new value), follow this excellent guide on PiMyLifeUp on setting up DNS on Raspbian OS.
Installing a VPN
- Install PiVPN by pasting the following command into the terminal (and hit enter):
curl -L https://install.pivpn.io | bash
- Run pivpn by typing it into the terminal.
- Follow the wizard.
- Hit Yes on the static IP address confirmation screen.
- Hit OK.
- Hit OK.
- Choose your user, hit OK.
- Hit OK.
- Choose Yes to enable automatic upgrades. (Highly recommended.)
- Choose UDP and hit OK.
- Enter a random port number not already used by another network service and hit OK. (We recommend setting a custom port to better enhance security against potential scans and attacks.)
- Confirm your port number by hitting Yes.
- Choose 2048-bit encryption and hit OK. (You can use 4096, but this would affect VPN performance.)
- Hit OK and wait a while for various VPN-related things to be installed and configured.
- Hit Yes when the installer asks you to use OpenVPN 2.4 if you know your favorite client supports it.
- Choose DNS Entry and hit OK. (Leave on public IP if you have a static IP address and did not set up DNS for external access.)
- Enter the custom DNS name for the VPN server.
- Choose a DNS provider.
- Hit Yes to reboot the Raspberry Pi.
Adding a user to the VPN
- Run the following in the terminal:
sudo pivpn add
- Enter an identifying name for the user.
- Set a secure password.
- Now you need to copy the .opvn files stored in /home/pi/ovpns to devices you wish to connect to the VPN. You can think of these as certificates. Use a USB to take them off the Pi or connect to the device using an SFTP client like FileZilla.
- Provided with the password and .opvn file, users will now be able to connect to the VPN.
Connecting to the VPN
- Download the OpenVPN client, or you can use your favorite alternative.
- Set up a new connection by importing the .opvn file and entering the user password.
- Connect, and you're now good to go!
The Raspberry Pi 4 is the latest iteration of the small computer from Raspberry, offering considerable computing performance for such a small package.
Samsung's EVO MicroSD range is excellent. The 32GB card is perfect for installing Raspbian OS, any apps we need on the device, and more.
We test and review VPN services in the context of legal recreational uses. For example:
1. Accessing a service from another country (subject to the terms and conditions of that service).
2. Protecting your online security and strengthening your online privacy when abroad.
We do not support or condone the illegal or malicious use of VPN services. Consuming pirated content that is paid-for is neither endorsed nor approved by Future Publishing.
Rich Edmonds is Senior Editor of PC hardware at Windows Central, covering everything related to PC components and NAS. He's been involved in technology for more than a decade and knows a thing or two about the magic inside a PC chassis. You can follow him over on Twitter at @RichEdmonds.
Thank you for signing up to Windows Central. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.