VPN’s are a great way to secure your browsing while connected to public wifi. A VPN is also useful for being able to access devices and files connected to your home network when you are not connected to your home wifi.

This tutorial will show you how to utilize PiVPN and Duck DNS to create your very own home VPN server. This tutorial is aimed at using a raspberry pi for the setup.

Duck DNS

The first part of the setup is to install Duck DNS. Duck DNS is a dynamic DNS service. What this means is that if/when your public IP address changes, Duck DNS will update to reflect that new address. The first step in setting up Duck DNS is setting a domain name. Once logged in, you will see an option to add a domain. Pick a domain name that you like, and click “add domain”.

Next, click on the install tab. Select linux cron and select your newly created domain from the drop down list at the bottom of the page. Duck DNS will give you step-by-step instructions on how to set up Duck DNS up on your raspberry pi to check for IP address changes every 5 minutes.


The next part of the setup is installing the VPN server software, PiVPN. The installation couldn’t be simpler. All you need to do is run the following command in a terminal and follow the prompts.

curl -L https://install.pivpn.io | bash

You will need to set up a static IP address which the installer will help you do. If you already have a static IP set that is fine, you can continue with your current settings.

When you get to the prompt Installation Mode, use the down arrow key to select OpenVPN and then press the space bar. Press enter to continue.

The installer will also ask you to set a port, feel free to change the port to whatever you would like, just make sure you write that port down as we will need to utilize it later on.

In the Public IP or DNS prompt, select DNS Entry and continue. Enter the Duck DNS domain name you created earlier.

Once you have finished the rest of the installation it is now time to add a vpn profile. Run pivpn add to do so. Follow the prompted commands and enter the values you would like.

Once completed your vpn profile file will be in the /ovpns file. This is the file you will use to connect your device to the vpn.

If you run a headless raspberry pi the easiest way to get this file from your raspberry pi to your device is to use sftp.

On another computer, open a terminal and use the normal ssh command to get into your pi but instead of typing ssh type sftp.

Once logged in, enter get /ovpns/yourfile.ovpn and the file will be copied to your computer.

Port Forwarding

The final step is to port forward the port you selected during the PiVPN installation on your router. This will allow you to connect to your VPN server from outside of your home network. As all routers have different ways of port forwarding, I will leave it up to you to figure out how to do that. If you cannot figure out, feel free to comment or send me an e-mail asking for assistance.

That’s it! You should now be able to connect to your home network when connected to outside networks!

Duck DNS