How to use your Raspberry Pi as home VPN server?

How to use your Raspberry Pi as home VPN server?

Written by Server Enthusiast on Jan 21st, 2021 Views Report Post


Paying a monthly fee for a VPN could be costly. What you could do instead is get a Raspberry Pi for a one time payment of ~$30 and setup your own home VPN server on your Raspberry Pi.

Of course networking and VPNs in general can be quite hard to setup and manage, especially if you do not have a lot of experience.

However, I recently discovered a tool called PiVPN which I believe offers the simplest way of setting up and managing a VPN server on Raspberry Pi.

PiVPN offers both WireGuard and OpenVPN as options. In this tutorial I use OpenVPN and will show you how to turn your Raspberry Pi into a VPN server and how to use your Phone to connect to that VPN anywhere you are.


Before you get started you would need a Raspberry Pi and a fresh Raspberry Pi OS (previously called Raspbian) installed.

You can download Raspberry Pi OS from here:


PiVPN offers a convenience script which would do all of the hard work for you so that you don't have to install any Kernel modules manually or follow a lengthy, complicated and confusing tutorials.

All that you need to do is to SSH to your Raspberry Pi and then run the following command:

curl -L | bash

Once you run the script it might take a while to complete as it does a lot of things including:

  • Update the APT repositories
  • Upgrade all packages
  • Install OpenVPN server in our case or WireGuard if you stick to the default

Managing your VPN

PiVPN comes with a nice set of tools that let you manage your VPN clients.

  • To add a new client you just need to run the following command:
pivpn add

This would generate a your_username.ovpn config file which you then need to use to connect to your VPN.

  • To revoke the access for a specific client run:
pivpn revoke
  • To list the available clients run:
pivpn list

Connecting to your PiVPN

First you would want to start by installing a OpenVPN client.

  • If you are using Linux for your desktop you could use apt to install the OpenVPN client:
apt install openvpn
mkdir -p /etc/openvpn/client
chown root:root /etc/openvpn/client
chmod 700 /etc/openvpn/client

Then copy the your_username.ovpn that was generated in the last step to your Linux Desktop and move it to the /etc/openvpn/client/ foler:

mv whatever.ovpn /etc/openvpn/client/

After that to connect to your VPN just run:

sudo openvpn /etc/openvpn/client/your_username.ovpn

If you are using Mac, I would recommend using the Tunnelblick client. You can follow the instructions from their official documentation on how to set it all up here.

OpenVPN on your Phone

You could also use your PiVPN and connect from your Phone.

If you have an Android phone, you can install the following OpenVPN Connect app here:

After that , click on 'Import' from the menu and choose the directory on your device where you stored the .ovpn file.

Then to connect, click on the profile under OpenVPN Profile and press Connect.

If you are using iOS, the procedure is quite similar. Start by installing the OpenVPN Connect app:

Then go to the app where you copied the .ovpn file to, select the file, find an icon or button to 'Share' or 'Open with', and choose to open with the OpenVPN app.


For more information make sure to check out the the PiVPN repository.

Also make sure to star and contribute to that amazing open-source project!

Comments (0)