Barton Bytes   Archives  About

Configure Pi Hole for DNS Over TLS

Protect your DNS traffic from snooping with DoT

Pi-hole Logo

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 pi-hole.conf, and paste the following content:

## DNS Over TLS, Simple ENCRYPTED recursive caching DNS, TCP port 853
## unbound.conf – original at
# edited by
access-control: allow
cache-max-ttl: 14400
cache-min-ttl: 600
do-tcp: yes
hide-identity: yes
hide-version: yes
minimal-responses: yes
prefetch: yes
qname-minimisation: yes
rrset-roundrobin: yes
ssl-upstream: yes
use-caps-for-id: yes
verbosity: 1
port: 5353
name: “.”
forward-addr: # primary
forward-addr: # cloudflare primary
forward-addr: # secondary
forward-addr: # 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 @ -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 /etc/pihole/setupVars.conf.

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.

Written on Aug 2, 2018.