Pi-hole on Raspberry Pi OS with dnscrypt-proxy


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.

  1. Install Raspberry Pi OS per the official instructions.
  2. Install Pi-hole on Raspberry Pi OS per the official instructions.
  3. Log into your Raspberry Pi locally or remotely using SSH.
  4. Run sudo apt update && sudo apt install dnscrypt-proxy to install dnscrypt-proxy.
  5. 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:
  6. Edit /etc/dnscrypt-proxy/dnscrypt-proxy.toml, setting listen_addresses = [] to use the systemd socket activation.
  7. 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.
  8. Run sudo systemctl restart dnscrypt-proxy.socket to restart the dnscrypt-proxy systemd socket process.
  9. Run sudo systemctl restart dnscrypt-proxy.service to restart dnscrypt-proxy.
  10. Run sudo systemctl restart pihole-FTL.service to restart FTLDNS.
  11. Log into the Pi-hole admin web interface.
  12. Navigate to Settings and from there to the DNS tab.
  13. 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 See this screenshot for an example. Click "Save" at the bottom.
  14. 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.
  15. If possible, reboot Pi-hole and ensure all services work as expected after a full system restart.
  16. 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

  1. Prime or Not Prime: That is the Question (2023-07-22)
  2. Switching Monitor Inputs on Computer Wakeup (2021-04-25)
  3. Changing the Playback Speed on Spotify's Web Player (2021-04-24)
  4. Solving Microcorruption Hollywood (2021-03-28)
  5. Font Rendering on macOS (2020-07-02)
  6. Video Disk Recorder (VDR) Tooling (2020-05-30)
  7. Spotify Web Player Failure due to Crash of Connected Device (2020-05-08)
  8. Malicious Forward Proxies (2020-04-27)
  9. Switching to a Dark Theme (2020-04-25)
  10. USB 3.0 to Gigabit Ethernet Adapter with Realtek 8153 Chipset on macOS Catalina (2020-04-23)
  11. Backing up Emails using OfflineIMAP (2020-04-19)
  12. Using a Raspberry Pi as a Wireless Access Point (2020-04-18)
  13. Accessing External Hard Drives in a Virtual Machine (2017-12-11)
  14. Managing Clipboards (2016-11-23)
  15. Multi-Screen Configuration Using Xrandr (2016-07-02)
  16. Email Backup and Migration using Thunderbird (2016-06-29)
  17. Automatic SSH Proxy Selection (2016-02-08)
  18. Set Color Temperature (2015-11-25)
  19. Completion Methods in Vim (2015-10-10)
  20. Fuzzing the mbed TLS Library (2015-09-26)
  21. SSH Weak Diffie-Hellman Group Identification Tool (2015-08-12)
  22. Building a Standing Desk for 50 Bucks (2015-01-25)
  23. High-DPI Displays under Linux (2014-12-23)
  24. Slow Wi-Fi on the Raspberry Pi (2014-06-15)
  25. XBMC on the Raspberry Pi (2014-06-14)
  26. Turning the Raspberry Pi into a Game Console (2014-06-12)
  27. ZFS Backups to External Hard Drives (2014-03-23)
  28. Display the I/O Usage of a Process (2014-02-21)
  29. Determining Wireless Network Channel Usage (2014-02-09)
  30. Managing Web Files through a Repository (2013-08-17)
  31. Simple HTTP File Servers (2013-08-16)
  32. Protect your SSH Private Keys (2013-06-16)
  33. Forward Secrecy for HTTPS and Ephemeral Diffie-Hellman (2013-06-14)
  34. Markdown Preview Chrome Extension (2013-06-13)