Open menu

How I setup my Pi-hole


Update: 2024/09/12

Pi-Hole Local DNS Records [A/AAAA]

I have since moved my config to Pi-Hole's Local DNS Records and Local DNS Records, as I now run a single instance and dont need to sync the config.


Pi-hole Custom Config

At home I run Pi-hole for ad blocking and also an internal DNS, I started off running DNSmasq before Pi-hole. But found Pi-hole to be the best of DNSmasq and ad blocking.

If you've not see or heard about Pi-hole, your missing out. Its a network-wide ad blocking, even in apps on your phone.

More about my setup

I run Pi-hole as 2 docker containers on 2 pis, they dont run on the swarm as I want them to run even if I mess up the swarm mode. I also run 2 so that I have failover if a docker host is restarted or crashes. They have their own /etc/pihole, but share /etc/dnsmasq.d. The main benifit of the dnsmasq share is that I have my custom config in there.

How to

The first step in my setup is to get 2 docker hosts up and running with a secondary IP, as the secondary IP will be the DNS IP used in DHCP. Then in my git repo with all my docker stacks and compose files, is the pihole-primary.yml and pihole-secondary.yml compose files to deploy pihole01 and pihole02. Both files are almost identical, except for service name and /etc/pihole dircetory.

How to inernal DNS

To get internal DNS, I have my own config in /etc/dnsmasq.d. Pi-hole has its config as 01-pihole.conf, so my config is 02-horwood.conf

To make DNS work for all my internal hosts, I have used the host-record option, this will give you both forward and reverse DNS in 1 setting -> man page. The other option I use is a cname, this allows you to setup your web server hostname and then cname any sites that run on it.

Look ma, DNS

Below is a snapshot of my custom config, as you can see I have some Pis and some sites.

# PIs
host-record=pi-snapcli01,snapcli01.shed.horwood.biz,192.168.49.200
host-record=pi-tv01,tv01.house.horwood.biz,192.168.49.201
host-record=pi-web2,web2.shed.horwood.biz,192.168.49.202

# Web sites
host-record=web.horwood.biz,192.168.49.150
host-record=web.horwood.local,192.168.49.151
cname=owncloud.horwood.biz,web.horwood.biz
cname=kb.horwood.biz,web.horwood.biz
cname=owncloud.deeks.biz,web.horwood.biz
cname=www.home.local,web.horwood.biz

Below you can see how that works for a host

matt@pi-docker01:~ $ host pi-web2
pi-web2 has address 192.168.49.202
matt@pi-docker01:~ $ host 192.168.49.202
202.49.168.192.in-addr.arpa domain name pointer pi-web2.

Now for a cname

matt@pi-docker01:~ $ host owncloud.horwood.biz
owncloud.horwood.biz is an alias for web.horwood.biz.
web.horwood.biz has address 192.168.49.150

Updating the config

The only thing that I need to work out now, is how to restart dnsmasq once I have updated my config. As the process is a faff.

  1. edit 02-horwood.conf
  2. get the container ID from docker docker ps| grep pihole
  3. connect to container and restart DNS docker exec -it <ID> pihole restartdns
  4. repeat steps 2 & 3 on second pihole

Published: 15 Sep 2020 by Matt Horwood