Files
EasyDNS/docs/secure-dns.md
T
2026-11-22 14:21:54 +01:00

120 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Encrypted DNS: DNS-over-TLS and DNS-over-HTTPS
EasyDNS speaks encrypted DNS in both directions:
| Direction | DNS-over-TLS (RFC 7858) | DNS-over-HTTPS (RFC 8484) |
|---|---|---|
| **Server** – your clients → EasyDNS | port 853, ALPN `dot`, many queries per connection (RFC 7766) | GET and POST on `/dns-query`, **HTTP/2** (multiplexed) and HTTP/1.1 (keep-alive), ALPN `h2`, `http/1.1` |
| **Client** – EasyDNS → upstream resolvers | pool of persistent connections per upstream | one persistent **HTTP/2** connection per upstream carrying all concurrent queries; HTTP/1.1 fallback |
TLS is rustls (TLS 1.2/1.3, no legacy ciphers). Server certificates are reloaded
automatically within 60 s after the files change (Let's Encrypt renewals need no
restart; a broken new pair is rejected and the old certificate stays in use).
## 1. Secure DNS server for your network (DoT + DoH)
```yaml
# /etc/easydns/config.yaml (additions to the default hybrid configuration)
tls:
cert_file: /etc/letsencrypt/live/dns.example.com/fullchain.pem
key_file: /etc/letsencrypt/live/dns.example.com/privkey.pem
dot_listen: ["0.0.0.0:853", "[::]:853"]
doh_listen: ["0.0.0.0:443", "[::]:443"]
recursion:
allowed_clients: ["acl:lan", "::1/128"] # who may resolve Internet names (also over DoT/DoH)
```
* The certificate must contain the name clients use (`dns.example.com`); IP-only
certificates work for clients that support them.
* The `easydns` user needs read access to the key:
`setfacl -m u:easydns:rx /etc/letsencrypt/{live,archive}` and
`setfacl -m u:easydns:r /etc/letsencrypt/archive/dns.example.com/privkey*.pem`
(or a certbot deploy hook that copies the pair to `/etc/easydns/tls/` with mode 0640
root:easydns).
* DoT/DoH clients go through the same policies as UDP/TCP: recursion ACL, rate limiting,
block lists, views. Authoritative zones are answered for everyone.
* Serving recursion over DoT/DoH to the whole Internet makes an open resolver; keep
`allowed_clients` to your networks (VPN users included) unless you really run a public
resolver.
* Behind a reverse proxy that terminates TLS (nginx, HAProxy, Caddy), use
`doh_plaintext_behind_proxy: true` and `doh_listen: ["127.0.0.1:8053"]`; HTTP/1.1 and
HTTP/2 cleartext (h2c, prior knowledge) are accepted. Note that ACLs then see the
proxy's address.
Limits per connection: 100 concurrent HTTP/2 streams, 64 KiB body, 8 KiB headers,
10 s to receive a request body, `server.tcp_idle_timeout` (minimum 30 s for DoH) for idle
connections, `server.max_tcp_connections` connections in total.
### Client configuration
| Client | Setting |
|---|---|
| Android 9+ | Settings → Network → Private DNS → `dns.example.com` (DoT) |
| Firefox | Settings → Privacy → DNS over HTTPS → Custom: `https://dns.example.com/dns-query` |
| Chrome / Edge | Settings → Privacy and security → Use secure DNS → Custom: `https://dns.example.com/dns-query` |
| Windows 11 | Settings → Network → DNS server assignment → DNS over HTTPS: Manual template `https://dns.example.com/dns-query` |
| systemd-resolved | `DNS=192.0.2.53#dns.example.com` and `DNSOverTLS=yes` in `/etc/systemd/resolved.conf` |
| iOS / macOS | a configuration profile with `DNSSettings` (`DNSProtocol` HTTPS or TLS, `ServerURL` / `ServerName`) |
| Another EasyDNS | `upstreams.servers: ["tls://192.0.2.53#dns.example.com"]` |
### Checking it
```bash
edot 192.0.2.53 example.com --tls-name dns.example.com # DoT, prints TLS version, ALPN, timings
edoh https://192.0.2.53/dns-query example.com --tls-name dns.example.com --http2 # DoH over HTTP/2
edoh https://192.0.2.53/dns-query example.com --tls-name dns.example.com --method get
```
`--ca file.pem` trusts a private CA, `--insecure` skips verification (diagnostics only).
## 2. Secure forwarder (encrypted upstreams)
Forward everything over DoT (nobody on the path – ISP, hotel Wi-Fi – sees or changes
your queries):
```yaml
resolution: { default: forward }
upstreams:
strategy: fastest # or failover / round-robin
timeout: 2s
servers:
- "tls://1.1.1.1:853#cloudflare-dns.com"
- "tls://9.9.9.9:853#dns.quad9.net"
- "https://[2606:4700:4700::1111]/dns-query#cloudflare-dns.com"
```
* The part after `#` is the certificate name; it is verified against the built-in
Mozilla root store. For an internal resolver with a private CA add
`upstreams.tls_ca_file: /etc/easydns/tls/internal-ca.pem`.
* Connections are kept open: DoT upstreams use a pool (up to 8 idle connections per
upstream, reused for 20 s), DoH upstreams multiplex all concurrent queries over one
HTTP/2 connection. A connection closed by the server is replaced transparently.
* `forward_zones` can mix transports, e.g. company zones over plain DNS inside the VPN and
everything else over DoT.
* Combine with `recursion` for `forwardthenrecursive` (encrypted first, own recursion as
fallback) – note that the fallback is unencrypted by nature of DNS recursion.
* DNSSEC: forwarded answers are passed through, not validated by EasyDNS itself; the
public resolvers above validate DNSSEC, and the encrypted channel protects their answers
on the way to you. (Own validation applies to `recursive` resolution.)
Measured on loopback (2 vCPU container, release build, sequential queries):
| Transport | per query |
|---|---|
| DoT, new connection per query | 0.48 ms |
| DoT, pooled connection | 0.06 ms |
| DoH HTTP/1.1, new connection per query | 0.46 ms |
| DoH HTTP/2, persistent | 0.13 ms |
Over a real network the saving per query is the TCP + TLS handshake, i.e. 2–3 round
trips (e.g. 40–60 ms to a resolver 20 ms away).
## 3. Port overview
| Port | Purpose | Exposure |
|---|---|---|
| 53/udp+tcp | plain DNS | LAN / Internet (authoritative) |
| 853/tcp | DoT | as needed |
| 443/tcp | DoH | as needed |
| 127.0.0.1:9953 | REST API / CLI | loopback only |
| 127.0.0.1:9090 | Prometheus metrics | loopback / monitoring network |