This will transform your server into a network wide ad-blocker as well as allowing you to use this ad-blocker from outside your network using the private VPN of PiVPN. These software are originally meant to be installed on a Raspberry Pi, but since you got a space on your server, why not install it? This is the easiest way to get OpenVPN server installed on your server. Did I mention that it’ll also block ads?

Do take note that some of the commands will be used without “sudo” while some are using it.

So as always, start by updating your server and installing required components:

sudo apt update
sudo apt upgrade
sudo apt install curl 

You can install either Pi-Hole or PiVPN first since we are going to install both and configure it in a way that will make them talk to each-other. On this occation, we’ll install PiVPN first.

Install PiVPN

curl -L | bash

The OS is untested? No issues, it’ll work fine. Click Yes.

Installer starting, click OK followed by OK, OK, OK until you arrive at the user selection screen.

Choose a user (the username you logged in as in your ubuntu other then root) followed by OK.

Ports need to open? OK.

Unattended security patches? Better to click Yes.

Protocol UDP is better as it is hidden from port scans, followed by OK.

Choose a custom port. Recommendations to change it to anything other then 1194, the default port. Best to choose a port number between 10,000 and 65,000.

Stronger encryption using OpenVPN 2.4? Yes please.

Encryption level of 256 is enough but you can choose higher since your server is more powerful then a Pi.

Now, if you are using a fixed IP, you can choose it. In our case, we will choose a DNS entry as it will allow us to connect even if the IP changes.

If you selected DNS entry, enter the dns entry here like:

Confirm the setting is correct by choosing Yes.

Choose a DNS provider here. You can choose anything as we will be changing it later. In our case, we’ll go with Cloudflare as it has a easy to recognize IP.

Do you need a custom domain? Choose No here.

And we are done! Click Ok.

Choose Yes followed by Ok to reboot.

Now it is time to install Pi-Hole.

Install Pi-Hole

curl -sSL | bash

Start the installer with Ok, Ok, and Ok again.

Time to choose an interface. Choose the first one that is NOT tun0. We’ll add it later in settings.

Choose a DNS provider you prefer for Pi-Hole to check and update it’s DNS records.

Default adblock list is fine for this step.

IPv4 and IPv6, choose the ones you need. Normally keeping both ON isn’t any issue.

Will you use existing network settings as static IP? Yes then Ok.

Do you need the admin web interface? Yes, so make sure On is checked before Ok.

Do you want to install lighttpd for the web interface? If you do not have apache or nginx installed or are not planning to installing them later, better to choose On and then Ok.

Log queries? Better to leave it On for troubleshooting.

Show everything, including passed and blocked domains and IPs that requested it? Yes.

Now let the installer do it’s thing before the completed screen with the confusing password appears.

First thing to do, change admin password…

pihole -a -p

Now you can access pi-hole admin interface on your IP or domain to check by going to or

Now lets make them talk to eachother…

Pi-Hole & PiVPN configuration

sudo nano /etc/openvpn/server.conf

Find the lines with your DNS provider IP address ( and in our case since we went with Cloudflare).

# Set your primary domain name server address for clients
push "dhcp-option DNS"
push "dhcp-option DNS"

and replace with

# Set your primary domain name server address for clients
push "dhcp-option DNS"

Then save and exit with Ctrl+x the Y then Enter.

Next edit the Pi-Hole configuration files:

sudo nano /etc/pihole/setupVars.conf

And add the line “PIHOLE_INTERFACE=tun0” bellow the existing “PIHOLE_INTERFACE=” line. Make sure it looks something similar to this.


The ens18 can be eth0 or something else depending on what your ethernet module is called. The tun0 must be added after that.

Then save and exit with Ctrl+x the Y then Enter.

Finally create a new file under dnsmasq to add the openvpn interface.

sudo nano /etc/dnsmasq.d/02-ovpn.conf



Then save and exit with Ctrl+x the Y then Enter.

Wait, you needed to add local domains to Pi-Hole? Lets do it now.

sudo touch /etc/hosts.mydomain
sudo nano /etc/dnsmasq.d/02-ovpn.conf



Then save and exit with Ctrl+x the Y then Enter.

Now go back and edit the hosts file we created:

sudo nano /etc/hosts.mydomain

And add your domains, one per line, IP followed by domain name like so:

Finally reboot your server:

sudo reboot

Final configurations

If you want to add users to your PiVPN, you can use the command:

pivpn add

All of your new OpenVPN configuration files will be saved at /home/username/ovpns/ directory.

You may want to configure additional blocklists for Pi-Hole:

Start by changing to pihole directory and editing the adlist file:

sudo nano /etc/pihole/adlists.list

Edit it to make it look like so (be sure to remove any tabs or spaces from the links)

Then save and exit with Ctrl+x the Y then Enter.

Also download the whitelist to this folder.

sudo cp whitelist.list /etc/pihole/whitelist.txt

Then update gravity.

pihole -g

Ensure everything is OK by looking at the green ticks.

Finally change your DNS to PiHole IP or start using PiVPN.