How to install & configure Ad-Blocking with Pi-Hole

In today’s tutorial I am going to talk you through the process of setting up an Ad-Blocking server (PI-Hole) on a virtual machine.

Benefits of blocking adverts

Although adverts are common place on websites and indeed provide a much needed income, they also slow down your browser experience quite extensively. This is not good especially if you are on a metered internet connection. Using an Ad-Blocker will speed up your browsing experience and also save you some data in the case that you are a using a metered connection.

The Ad-Blocking server which we are going to install today is called Pi-Hole. For more information about the software and how you can support it’s development can be found by visiting https://pi-hole.net/

To install PI-Hole we need to:

  • Configure Ubuntu server to use a static IP address on the network.
  • Download and install PI-Hole.
  • Configure your router to point to the Pi-Hole server.

For the puroposes of this tutorial I’m going to assume that you know how to setup, configure and install Ubuntu server either on a stand-alone machine or as a virtual machine.

Create a static IP address

There are 2 ways that you can create a static IP address, either reserving an IP address on your router or by specifically configuring Ubuntu server via netplan to use a static IP address.

I prefer to use the method out-lined in a previous post called how to setup a static IP address on Ubuntu 16.04 as my router only allows a certain amount of address reservations.  If you are using Ubuntu Server 17.10 then you will want to read this article called how to setup a static IP addresson Ubuntu 17.10 before proceeding as the method of setting a static IP address has changed.

Download and install Pi-Hole

There are various ways that you can install Pi-Hole. The easiest way to do this is to execute the following command:

curl -sSL https://install.pi-hole.net | bash

This method of “piping bash” causes a bit of controversy because you cannot read the code that is about to be run on your system therefore you could consider it a security risk. If you are determined to use this installation method then browse to the Pi-Hole website https://pi-hole.net/

Clone the Repository

You can also clone the Pi-Hole repository by running the following commands:

git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
cd "Pi-hole/automated install/"
sudo bash basic-install.sh

Download the installer

Another method is to manually download the installer and run. You can do this by executing the following commands:

wget -O basic-install.sh https://install.pi-hole.net
sudo bash basic-install.sh

Configuration

Once you have completed the install by your chosen install method you will need to configure your router to use Pi-Hole as a DNS server. This will this will ensure that all devices within your network will connect to the internet via the Pi-Hole server. Configuring your router is beyond the scope of this tutorial, however, there is a really good guide called How do I configure my devices to use Pi-hole as their DNS server?

If for any reason your router does not allow setting your own DNS then you can use Pi-Holes’s own DNS server. Alternatively, you could manually point your device to the Pi-Hole DNS address.