Pi-hole is a free and open source software to block Internet ads and tracking domains. The most significant advantage is ad blocking on all devices on the network from your smartphone to your tablets including all desktop computers and apps. This page shows how to configure Cloudflare DNS over HTTPS service along with Pi-Hole server running on Ubuntu Linux 18.04 LTS.
Pi-hole DNS over HTTPS
DNS over HTTPS (DoH) is a protocol for DNS resolution through the HTTPS protocol. DoH increase your user’s privacy and security and help prevent manipulation of DNS.
How to configure Pi-hole for Cloudflare DNS
There are numerous DNS over HTTPS (DoH) clients you can use to connect to Cloudflare DNS server IP address 220.127.116.11 and 18.104.22.168. We are going to use Cloudflared by downloading .deb package for Ubuntu. Type the following wget command:
How to add a new Ubuntu Linux user for cloudflared
In order to configuring cloudflared to run on startup, first add a new Linux user named cloudflared using the useradd command:
sudo useradd -r -M -s /usr/sbin/nologin -c "Cloudflared user" cloudflared
Verify that user has been created with the help of grep command and /etc/passwd:
grep '^cloudflared' /etc/passwd
Alternatively, one can use the id command as well on Ubuntu to verify cloudflared user account:
Lock down the Linux account named cloudflared:
sudo passwd -l cloudflared
sudo chage -E 0 cloudflared
You can see account aging information, run chage command:
sudo chage -l cloudflared
How to configuring cloudflared dns
Create a file named /etc/default/cloudflared as follows using text editor such as vim command or nano command:
sudo vi /etc/default/cloudflared
Append the following text:
## args for cloudflared ## ## 5353 is localhost:5353. This is where dns queries are sent by pi-hole ## ## 22.214.171.124 and 126.96.36.199 are Cloudflare DNS servers ## CLOUDFLARED_OPTS=--port 5353 --upstream https://188.8.131.52/dns-query --upstream https://184.108.40.206/dns-query
Save and close the file in vim.
Set up permission using chown command:
sudo chown -v cloudflared:cloudflared /usr/local/bin/cloudflared /etc/default/cloudflared
changed ownership of '/usr/local/bin/cloudflared' from root:root to cloudflared:cloudflared changed ownership of '/etc/default/cloudflared' from root:root to cloudflared:cloudflared
How to create systemd startup script for Cloudflared
Type the following command:
sudo vi /lib/systemd/system/cloudflared.service
Append the following config:
[Unit] Description=cloudflared DoH proxy After=syslog.target network-online.target [Service] Type=simple User=cloudflared EnvironmentFile=/etc/default/cloudflared ExecStart=/usr/local/bin/cloudflared proxy-dns $CLOUDFLARED_OPTS Restart=on-failure RestartSec=10 KillMode=process [Install] WantedBy=multi-user.target
Enable and start the cloudflared service
Run the following systemctl command:
sudo systemctl enable cloudflared
sudo systemctl start cloudflared
sudo systemctl status cloudflared
Save and exit from the vim.
Verify that cloudflared working
Configure Ubuntu Pi-hole for Cloudflare DNS over HTTPS
Now, everything is set up and running. Hence, it is time to configure Pi-hole to use the local cloudflared service running on 127.0.0.1 port 5353. Fire the web browser and type the pi-hole admin url as per your setup. In my case my OpenVPN and pi-hole running on 10.8.0.1, hence I type:
Click on the Settings > DNS > Choose Custom 1 (IPv4) under Upstream DNS Servers and enter “127.0.0.1#5353” > Scroll down and click on the Save button.