Skip to content

Commit cade63f

Browse files
committed
Add guide for DNS-Over-HTTPS (DoH) using dnscrypt-proxy
Signed-off-by: Fabian Foerg <[email protected]>
1 parent bae942c commit cade63f

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

docs/guides/dns/dnscrypt-proxy.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
## Configuring DNS-Over-HTTPS using `dnscrypt-proxy` [^guide]
2+
3+
To utilize DNS-Over-HTTPS (DoH) or other encrypted DNS protocols with Pi-hole, preventing man-in-the-middle attacks between Pi-hole and upstream DNS servers, the following sections explain how to install the flexible and stable [dnscrypt-proxy](https://github.com/DNSCrypt/dnscrypt-proxy) tool.
4+
5+
As an alternative tool to this end, consider [cloudflared](https://github.com/cloudflare/cloudflared), for which a [guide](cloudflared.md) exists as well.
6+
7+
### Installing `dnscrypt-proxy`
8+
9+
Raspberry Pi OS and Debian as well as Ubuntu come with packages for `dnscrypt-proxy`, which makes its installation a breeze:
10+
11+
```shell
12+
sudo apt update
13+
sudo apt install dnscrypt-proxy
14+
```
15+
16+
### Configuring `dnscrypt-proxy`
17+
18+
By default, `FTLDNS` listens on the standard DNS port 53.
19+
20+
To avoid conflicts with `FTLDNS`, edit `/usr/lib/systemd/system/dnscrypt-proxy.socket`, ensuring `dnscrypt-proxy` listens on a port that is not in use by other services.
21+
22+
The following settings in `/usr/lib/systemd/system/dnscrypt-proxy.socket`, let `dnscrypt-proxy` listen on localhost on port 5053:
23+
24+
```
25+
ListenStream=127.0.0.1:5053
26+
ListenDatagram=127.0.0.1:5053
27+
```
28+
29+
If you have `cloudflared` installed, you may uninstall it, as `dnscrypt-proxy` will replace it, or choose a unique port for `dnscrypt-proxy`.
30+
31+
Also edit `/etc/dnscrypt-proxy/dnscrypt-proxy.toml`, updating the following settings:
32+
33+
```toml
34+
# Use systemd socket activation:
35+
listen_addresses = []
36+
37+
# Populate `server_names` with desired DoH/DNSCrypt upstream DNS servers listed in https://dnscrypt.info/public-servers/.
38+
# Example for Cloudflare malware-blocking DNS:
39+
server_names = ['cloudflare-security']
40+
```
41+
42+
### Configuring Pi-hole Upstream DNS Servers
43+
44+
Run the following command to set the upstream DNS server of Pi-hole to your local `dnscrypt-proxy` instance:
45+
46+
```shell
47+
sudo pihole-FTL --config dns.upstreams '["127.0.0.1#5053"]'
48+
```
49+
50+
### Restarting Services
51+
52+
Run the following commands to restart `dnscrypt-proxy` and `FTLDNS`:
53+
54+
```shell
55+
sudo systemctl restart dnscrypt-proxy.socket
56+
sudo systemctl restart dnscrypt-proxy.service
57+
sudo systemctl restart pihole-FTL.service
58+
```
59+
60+
### Reviewing Service Status
61+
62+
Run the following commands to review the status of each restarted service:
63+
64+
```shell
65+
sudo systemctl status dnscrypt-proxy.socket
66+
sudo systemctl status dnscrypt-proxy.service
67+
sudo systemctl status pihole-FTL.service
68+
```
69+
70+
Each service is expected to be in active (running) state.
71+
Review the log files shown if a service didn't restart successfully.
72+
73+
### Configuring Pi-hole
74+
75+
Optionally, confirm in the Pi-hole admin web interface that upstream DNS servers are configured correctly:
76+
77+
* Log into the Pi-hole admin web interface.
78+
* Navigate to "Settings" and from there to "DNS".
79+
* Under "Upstream DNS Servers", uncheck all boxes for public DNS servers.
80+
* Under "Upstream DNS Servers", ensure the box is filled with the IP address and port combination `dnscrypt-proxy` listens on, such as `127.0.0.1#5053`.
81+
* Click on `Save` at the bottom.
82+
83+
### Updating `dnscrypt-proxy`
84+
85+
Since you installed `dnscrypt-proxy` via APT, updating `dnscrypt-proxy` is a matter of running the following commands:
86+
87+
```shell
88+
sudo apt update
89+
sudo apt upgrade
90+
```
91+
92+
### Uninstalling `dnscrypt-proxy`
93+
94+
To uninstall `dnscrypt-proxy`, run the command `sudo apt remove dnscrypt-proxy`.
95+
Update the Pi-hole DNS settings to use another upstream DNS server.
96+
97+
[^guide]: Guide based on [this guide by Fabian Foerg | ffoerg.de](https://ffoerg.de/posts/2024-01-28.shtml)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ nav:
175175
- 'DNS':
176176
- 'unbound': guides/dns/unbound.md
177177
- 'cloudflared (DoH)': guides/dns/cloudflared.md
178+
- 'dnscrypt-proxy (DoH)': guides/dns/dnscrypt-proxy.md
178179
- 'Upstream DNS Providers': guides/dns/upstream-dns-providers.md
179180
- 'VPN':
180181
- 'WireGuard':

0 commit comments

Comments
 (0)