In this tutorial we will walk through how to install and setup PiHole for an Ubuntu Linux distribution. Filtering your network traffic via PiHole is beneficial if you need to block certain, potentially malicious, DNS queries, advertising sites, internet trackers and websites that should be age restricted. Physically It works at the network-level where it acts as a DNS sink-hole, rather than at the application level like AdGuard.
This tutorial is based on setting up PiHole on a DigitalOcean Ubuntu 18.04 x64 droplet. You can either create your own Ubuntu droplet to follow the steps exactly as described then destroy it; or roll your own Ubuntu setup on an old laptop or desktop with Ubuntu 18.04 installed if you prefer.
Once you have your Ubuntu 18.04 system setup open a terminal or if your have created a Ubuntu 18.04 VPS setup ssh into the droplet. Then work through the following steps to install PiHole on Ubuntu 18.04.
Step 1: Configure Ubuntu for PiHole
We need to first of all update the VPS so it is primed to install PiHole correctly. To do this run the following command to update the Ubuntu package repositories and upgrade the system.
apt-get update && sudo apt-get upgrade -y
Next we need to install the required packages to install PiHole. This is actually just to install git on Ubuntu as we don’t need to compile PiHole from source like we had to in the tutorial on installing Reddis on Ubuntu.
apt-get install git
From here, we need to setup up a static IP on the system by opening and editing the file /etc/network/interfaces in vim as follows.
In the file, search for the text auto eth0 using the vim backslash search function. You will find two lines as shown.
auto eth0 iface eth0 inet dhcp
Change the text to the following text by cutting and pasting.
auto eth0 iface eth0 inet static address 192.168.1.15 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 18.104.22.168 22.214.171.124
To finish this step save and exit vim, then reboot Ubuntu.
shutdown -r now
Step 2: Install PiHole on Ubuntu
This step first requires you to ssh and reconnect to your VPS as it was rebooted in the last preparation step. Next we need to use git to download the PiHole files from GitHub for installation, then change into the repository directory.
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole cd Pi-hole/automated\ install/
Now run the PiHole installation Bash script to being installing PiHole as follows.
PiHole installer configuration selections
You will be prompted for your sudo password, then a dialog will inform you that you are about to install PiHole, just press Enter to confirm and proceed.
Next you will be prompted to select the upstream DNS provider you want to use, go ahead and select an appropriate choice. You can use OpenDNS if you are not sure.
Select Ok and Yes for the next two dialogs. Then select Yes to use a web interface for PiHole and Ok to enable logging on the next dialog.
Lastly, you will asked about your firewall setup and if you want to add firewall rules to allow HTTP TCP port 80 and DNS TCP and UDP port 53 access. Select Yes to enable these. The final dialog will show a password for the web interface, take note of this for later.
Step 3: Setup Ubuntu firewall access for PiHole
You should be able to access the web interface now as the firewall will allow HTTP access. However, we need the UFW rules and ports to open every time the system is started. To enable this run the following commands.
ufw allow http ufw allow 53
Everything should be installed and setup correctly if you have followed the steps above correctly.
Step 4: Configure your routers
The next setup is to update your own network setup to point to your Ubuntu system now running PiHole. Basically, this means changing your router’s DNS configuration settings to your server’s IP so all traffic is routed through it and DNS look-ups performed via it.
This depends on your own setup and will differ for each router or network device.
But, once you’ve updated your back-end network devices you arer all setup to use PiHole and can carry out any supplementary and necessary tasks via the web interface at http://vpsip/admin. Such as adding additional blocklists to filter certain sites.
That is all there is to installing and setting up PiHole on Ubuntu 18.04 Linux. We have worked through the various steps of prepping Ubuntu and the running the installer script. This tutorial used a DigitalOcean Ubuntu 18.04 VPS droplet, but you can easily adapt it to your own setup and needs.