Pi-hole on Raspberry Pi OS with dnscrypt-proxy
2024-01-28
Note: A condensed version of this guide is available from https://github.com/pi-hole/docs/pull/990.
Pi-hole is a software suite facilitating the installation and configuration of your own DNS resolver with filtering capabilities on your local network, preventing domains associated with unwanted content, such as malware and advertisements, from being resolved. Pi-hole can be installed in a Docker container as well as on several Linux distributions, including Raspberry Pi OS.
By default, Pi-hole uses its own forwarding DNS server named FTLDNS, which is based on the venerable dnsmasq. While FTLDNS is lightweight and stable, it lacks support for encrypted DNS protocols, such as as DNS-over-HTTPS (DoH), rendering DNS traffic between Pi-hole and upstream DNS servers susceptible to eavesdropping and modification by attackers in a man-in-the-middle position. To this end, the Pi-hole project provides instructions for installing a forwarding DNS server that supports DoH called cloudflared. While cloudflared can be configured with upstream DNS services beyond Cloudflare, Raspberry Pi OS lacks a package for it, requiring efforts to keep cloudflared updated.
Fortunately, Raspberry Pi OS maintains a package for the flexible and stable dnscrypt-proxy that supports DoH among other DNS protocols with encryption. The steps below illustrate how dnscrypt-proxy can be installed and configured to work with Pi-hole on Raspberry Pi OS. Note that while dnscrypt-proxy takes care of encrypting DNS traffic between Pi-hole and upstream DNS services on the internet, traffic between client devices and Pi-hole remains unencrypted and is susceptible to man-in-the-middle attacks.
- Install Raspberry Pi OS per the official instructions.
- Install Pi-hole on Raspberry Pi OS per the official instructions.
- Log into your Raspberry Pi locally or remotely using SSH.
- Run sudo apt update && sudo apt install dnscrypt-proxy to install dnscrypt-proxy.
- By default, FTLDNS listens on the standard DNS port 53.
To avoid conflicts, edit /usr/lib/systemd/system/dnscrypt-proxy.socket to ensure dnscrypt-proxy listens on a port that is not in use by other services, such as port 5335.
Specifically, the following settings, let dnscrypt-proxy listen on localhost on port 5335:
ListenStream=127.0.0.1:5335 ListenDatagram=127.0.0.1:5335
- Edit /etc/dnscrypt-proxy/dnscrypt-proxy.toml, setting listen_addresses = [] to use the systemd socket activation.
- Edit /etc/dnscrypt-proxy/dnscrypt-proxy.toml, setting server_names to the desired upstream DNS services. A list of servers with supported protocols is available from https://dnscrypt.info/public-servers/. For example, the setting server_names = ['cloudflare-security'] configures Cloudflare DNS with malware blocking as the DNS resolver with DoH.
- Run sudo systemctl restart dnscrypt-proxy.socket to restart the dnscrypt-proxy systemd socket process.
- Run sudo systemctl restart dnscrypt-proxy.service to restart dnscrypt-proxy.
- Run sudo systemctl restart pihole-FTL.service to restart FTLDNS.
- Log into the Pi-hole admin web interface.
- Navigate to Settings and from there to the DNS tab.
- Under "Upstream DNS Servers" on the left, uncheck all boxes for public DNS servers. Under "Upstream DNS Servers" on the right, check only the box for "Custom 1 (IPv4)" and fill the box with the IP address and port dnscrypt-proxy listens on, such as 127.0.0.1#5335. See this screenshot for an example. Click "Save" at the bottom.
- Configure other settings, such as Adlists. Since FTL v5.22, Pi-hole supports the Adblock Plus (ABP) syntax for domain filter lists. Several filter lists, including several of the lists used by uBlock Origin (uBO) are available in ABP syntax.
- If possible, reboot Pi-hole and ensure all services work as expected after a full system restart.
- Configure your router (and devices if necessary) to use Pi-hole for DNS per the official instructions.
Permanent Link for Post
Pi-hole on Raspberry Pi OS with dnscrypt-proxy (2024-01-28)
Older Posts
- Prime or Not Prime: That is the Question (2023-07-22)
- Switching Monitor Inputs on Computer Wakeup (2021-04-25)
- Changing the Playback Speed on Spotify's Web Player (2021-04-24)
- Solving Microcorruption Hollywood (2021-03-28)
- Font Rendering on macOS (2020-07-02)
- Video Disk Recorder (VDR) Tooling (2020-05-30)
- Spotify Web Player Failure due to Crash of Connected Device (2020-05-08)
- Malicious Forward Proxies (2020-04-27)
- Switching to a Dark Theme (2020-04-25)
- USB 3.0 to Gigabit Ethernet Adapter with Realtek 8153 Chipset on macOS Catalina (2020-04-23)
- Backing up Emails using OfflineIMAP (2020-04-19)
- Using a Raspberry Pi as a Wireless Access Point (2020-04-18)
- Accessing External Hard Drives in a Virtual Machine (2017-12-11)
- Managing Clipboards (2016-11-23)
- Multi-Screen Configuration Using Xrandr (2016-07-02)
- Email Backup and Migration using Thunderbird (2016-06-29)
- Automatic SSH Proxy Selection (2016-02-08)
- Set Color Temperature (2015-11-25)
- Completion Methods in Vim (2015-10-10)
- Fuzzing the mbed TLS Library (2015-09-26)
- SSH Weak Diffie-Hellman Group Identification Tool (2015-08-12)
- Building a Standing Desk for 50 Bucks (2015-01-25)
- High-DPI Displays under Linux (2014-12-23)
- Slow Wi-Fi on the Raspberry Pi (2014-06-15)
- XBMC on the Raspberry Pi (2014-06-14)
- Turning the Raspberry Pi into a Game Console (2014-06-12)
- ZFS Backups to External Hard Drives (2014-03-23)
- Display the I/O Usage of a Process (2014-02-21)
- Determining Wireless Network Channel Usage (2014-02-09)
- Managing Web Files through a Repository (2013-08-17)
- Simple HTTP File Servers (2013-08-16)
- Protect your SSH Private Keys (2013-06-16)
- Forward Secrecy for HTTPS and Ephemeral Diffie-Hellman (2013-06-14)
- Markdown Preview Chrome Extension (2013-06-13)