Self-hosted VPN server on Raspberry Pi

In this article I will explore the possibility to create a self hosted VPN server. I will be using OpenVPN server on a Raspberry Pi 3 running Raspbian. The purpose of using a self hosted VPN server is not to hide my traffic from my ISP, but to add a privacy layer on my traffic when I connect to the Internet from open wireless networks, such as open WiFi in Hostels, Airports, Restaurants and others. By connecting my mobile device(s) to my VPN server hosted at home. In this article I will demonstrate the setup of OpenVPN itself but also the few steps necessary to get my VPN server accessible via the Internet using a regular web address (eg. and the setup of one mobile device and connection tests.

The content of this article was written with an educative purpose only. I do not recommend to use this information in a production environment. I will not take and/or accept responsibility to any kinds of damage caused to your infrastructure, your system, your business, your customers, your life, your health or anything else. If you are using information in this article for other purpose than education and curiosity: You are the sole responsible and reliable person if something may happen.

I’m starting this from a fresh and clean installation of Raspbian image for this project. So, let’s download the lastest Raspbian image from website, personally I always download the Lite version. Once your download is completed, you can write it to an SD card or a microSD card by following instructions available in this article.

Writing a Raspberry Pi image on SD card

Identifying the SD Card mounting point to write the Raspberry Pi system image. Start by opening a command line as Root, and type the command lsblk to get existing list of available drive(s).

The usage of this information can damage your current system. Please use care and make sure to follow recommendations, advices and also your own analysis before proceeding. I will not take responsibility for any damage you may cause following these instructions. You will be the sole responsible in case of misuse.

arnaud@VBM-Testing: ~$ sudo su
[sudo] password for arnaud:
root@VBM-Testing:/home/arnaud# lsblk
sda      8:0     0     60G    0   disk   
-sda1    8:1     0     60G    0   part   /
sr0     11:0     1   1024M    0   rom

Then connect the SD Card by plugging it into the SD Card reader and type the same command again, lsblk. We will now get the SD Card information by comparison.

root@VBM-Testing:/home/arnaud# lsblk
sda      8:0     0     60G    0   disk   
-sda1    8:1     0     60G    0   part   /
sdb      8:16    1   15.1G    0   disk
-sdb1    8:17    1   15.1G    0   part   /media/arnaud/SD16GB
sr0     11:0     1   1024M    0   rom

Here we can see a new device in the list, name sdb, with 1 partition on it: sdb1. That is a SD Card as it is the only device we connected in between. We can also see the partition is mounted. We need to un-mount them with umount command.

root@VBM-Testing:/home/arnaud# umount /media/arnaud/SD16GB

Note 1: The SD card was already imaged with a Raspbian image, that I wasn’t using anymore, you may see only 1 partition on the SD Card that have the size of the entire SD Card.

Note 2: Raspbian project has been renamed “Raspberry Pi OS” but it is none the less the same thing. As running the command on a “Raspberry Pi OS” cat /etc/os-release provide the following results and Raspbian naming is still all around. Don’t get confused by that in the near future. It is also very possible that changes later as well.

cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION="10 (buster)"

We need to extract it from the zip file we downloaded before we can write it to the SD card, for that we will use unzip command. The file will be extracted in the current folder with command below (eg. /home/arnaud/ in this example).

root@VBM-Testing:/home/arnaud# unzip Downloads/

We can now write the Raspberry Pi image to the SD Card using the command dd. This command will copy 4MB bs=4M at the time, from the source image if=2019-04-08-raspbian-stretch-lite.img to the SD Card of=/dev/sd. It will done synchronously with conv=fsync (meaning it will finish to write on the SD Card before reading the next 4MB of the image source) and status=progress will also display progression of the entire process.

root@VBM-Testing:/home/arnaud# dd bs=4M if=2019-04-08-raspbian-stretch-lite.img of=/dev/sdb conv=fsync status=progress

Progression will look like this:

448790528 bytes (449 MB, 428 MiB) copied, 14 s, 31.1MB/s

Note 3: Soon I will add a new article with my preferred 1st steps after getting the SD Card ready, those are definitely options but as mentioned my preferred steps before booting the OS for the 1st time. That article will be linked about here at the end of this article (just be patient for that one if you land here before I write it).

Once copy is completed it will return to regular prompt. The SD Card may mount automatically again, dismount it in this case, and remove it from the computer. We are now ready to boot from it using the Raspberry Pi.