Configure Pi Hole for DNS Over TLS
Protect your DNS traffic from snooping with DoT
Pi-hole is a wonderful program for both technical and non-technical users to run a local DNS caching server, allowing you to block malicious and ad-serving domains. One of the fundamental flaws of DNS is the lack of encryption or integrity, which allows your ISP to snoop DNS traffic or spoof a DNS response. DNS-over-TLS will not completely solve these problems (see the end of this tutorial), but it provides a step in the right direction. Let’s get started.
Pi-hole uses dnsmasq as it’s DNS server. To use DoT, we will actually need to run an additional DNS server, Unbound, that provides this feature. To install on a debian-based system, run the following:
sudo apt install unbound
Once installed, navigate to the Unbound configuration folder at
/etc/unbound/unbound.conf.d/. Create a new file named
paste the following content:
## DNS Over TLS, Simple ENCRYPTED recursive caching DNS, TCP port 853
## unbound.conf – original at https://calomel.org/unbound_dns.html
# edited by bartonbytes.com
access-control: 127.0.0.0/8 allow
forward-addr: 220.127.116.11@853 # quad9.net primary
forward-addr: 18.104.22.168@853 # cloudflare primary
forward-addr: 22.214.171.124@853 # quad9.net secondary
forward-addr: 126.96.36.199@853 # cloudflare secondary
You’ll notice that this DNS server is configured to be accessible only on the local machine. It will open up port 5353. The config file includes the Quad9 and Cloudflare upstream DNS servers, which you can change or add to if necessary.
Make sure that Unbound is running:
sudo systemctl start unbound && sudo systemctl enable unbound
To test that Unbound can fulfill your DNS requests, run the following
dig command. If dig is not installed, run
sudo apt install dnsutils -y
dig @127.0.0.1 example.com -p 5353
Now, we need to tell Pi-hole’s dnsmasq to use this local port as it’s upstream DNS server. Due to a bug in the Pi-hole web application,
this must be done directly in the configuration file, found at
Locate the line
PIHOLE_DNS_1=, and change it to the following:
Remove any other
PIHOLE_DNS lines in the file. Now we can restart Pi-hole:
sudo systemctl restart pihole-FTL
… and voila! The upstream DNS requests sent from your Pi-hole will be encrypted using TLS.
As mentioned earlier, DNS-over-TLS is not a perfect solution to your privacy concerns. No matter how you protect your DNS traffic, the name of the websites that you visit will still be visible in the SNI of your HTTPS traffic, allowing your ISP (and any other intermediary) to view it. DoT somewhat protects integrity by preventing intermediaries from manipulating your DNS requests or their responses. However, you are still trusting the upstream DNS server- in our case, Quad9 and Cloudflare- to provide the correct responses.
Another option to secure DNS traffic is DNS-over-HTTPS. I chose DoT because the
cloudflared program would not work on my Raspberry Pi 1 Model B+. DoH has the advantage of being harder to block or detect, because the DNS traffic is encapsulated inside of HTTPS traffic destined for port 443. This is also a slight disadvantage due to the additional traffic overhead of the HTTPS headers, which makes DoH somewhat slower than DoT.