Skip to main content
  1. My Blog Posts and Stories/

Home Lab: Pi Hole

··852 words·4 mins

As part of my home lab series, I will be writing a series of blog posts on how to set up different home lab components. In today’s blog post, I will be writing about how to setup Pi Hole.

What is Pi Hole? #

Pi Hole is a DNS sinkhole that blocks ads on your network. It acts as a DNS server between your devices and the internet.

It contains many features, listed below (non-exhaustive):

  1. Block websites in a network wide format
  2. Local DNS records to resolve to your local services
  3. Improve network performance
  4. Analytics of your network
  5. Run your DHCP Server

How does it work #

There are 2 different situations when we query Pi Hole

  1. When we query a website that is not in the block list
  2. When we query a website that is in the block list

Query a website not in the block list. #

This also applies when we set a local CNAME record to resolve to a local service.

sequenceDiagram actor Client box Local participant Pi Hole participant Client end Client ->> Pi Hole: DNS Query 1 activate Pi Hole Pi Hole ->> DNS Server: DNS Query 1 activate DNS Server DNS Server ->> Pi Hole: DNS Response 1 deactivate DNS Server Pi Hole ->> Client: DNS Response 1 deactivate Pi Hole Client ->> Pi Hole: DNS Query 2 activate Pi Hole Pi Hole ->> Client: DNS Response 2 (Cached) deactivate Pi Hole
  1. Our Client devices will query Pi Hole for DNS resolution.
  2. As the website is not in the block list, Pi Hole will forward the DNS query to the DNS Server.
  3. The DNS Server will respond with the IP address of the website.

For more information on caching, please refer to this page.

Query a website that is in the block list. #

sequenceDiagram actor Client box Local participant Pi Hole participant Client end Client ->> Pi Hole: DNS Query activate Pi Hole Pi Hole ->> Client: DNS Response with empty query (Cached) deactivate Pi Hole
  1. Our Client devices will query Pi Hole for DNS resolution.
  2. As the website is in the block list, Pi Hole will respond with an empty query.
  3. This will cause the client to not be able to connect to the website.

Setting up Pi Hole #

In this tutorial, I will be showing you how to setup Pi Hole through a docker container.

Prerequisites #

  1. A host with the following ports 53/udp (used by DNS Service)
  2. Docker installed on the host

Step 1: Run the docker command #

docker run -dt --name pihole \
    -p 53:53/tcp \ # Port of DNS service
    -p 53:53/udp \ # Port of DNS service
    -p 80:80 \  # Port of the web service that you want.
    -e TZ="Asia/Singapore" \ # Timezone of your location
    -e FTLCONF_LOCAL_IPV4="<ip_addr_of_host>" \ # IP address of the host
    -e WEBPASSWORD="password" \ # Password for the web interface
    -v "$(pwd)/etc-pihole/:/etc/pihole/" \ # Volume for Pi Hole configuration
    -v "$(pwd)/etc-dnsmasq.d/:/etc/dnsmasq.d/" \ # Volume for DNSMasq configuration
    -restart=unless-stopped \

This command will run the docker container in the background. Wait for a few minutes for the container to start up.

Step 2: Login to your Pi Hole instance #

Access the web interface at http://<ip_addr_of_host>:<mapped_port>/admin/ and login with the password that you have set in the docker command.

Login Page
Login Page

Login with the password that you have set in the docker command.

Step 3: Configure your Pi Hole (Upstream DNS Servers) #

Dashboard
Dashboard

After logging in, you will see something like this. Click on the Settings tab at the bottom left hand side of the page.

DNS Settings
DNS Settings

  1. Click on the DNS tab at the top of the page.
  2. Edit the Upstream DNS Servers and update the different DNS services that you want upstream.

Step 4: Adding Local DNS Records #

Local DNS Records
Local DNS Records

  1. Click on the Local DNS Records tab at the side of the page.
  2. Click on DNS Records
  3. Fill up the domain and IP address that you want to resolve to.
  4. Click on Add and it should be added to the list.

Step 5: Configure your router to use Pi Hole #

This step depends on your router. For this example, I will be showing how to do it on an ASUS router.

ASUS Router
ASUS Router

  1. After logging into the router, you will be greeted in this main page.
  2. Click on WAN at the side of the page.

ASUS WAN Page
Asus WAN Page

  1. Click on No for Connect to DNS Server automatically
  2. This should reveal a new option to specify your DNS Server

ASUS DNS Setup
ASUS DNS Setup

  1. Fill up the DNS Server with the IP address of your Pi Hole instance.

Note: Please do not key in an alternate DNS Server it will cause the router to query either DNS Servers randomly.

Conclusion #

In this blog post, I have shown you how to setup Pi Hole on your home network. I have also shown you how to configure your router to use Pi Hole as the DNS Server.

Through this, you will be able to block ads on your network and also resolve to your local services.

  1. Pi Hole official website
  2. Pi Hole Docker Hub