DNS加密完全指南
DNS Resolution Protocol Comparison
| Protocol | Port | Transport | Encryption | Visible to ISP | Anti-Tamper | Latency | RFC |
|---|---|---|---|---|---|---|---|
| Plain DNS | 53 | UDP/TCP | None | Fully visible | No | Lowest | 1035 |
| DNSSEC | 53 | UDP/TCP | None (signed) | Visible | Yes | Low | 4033 |
| DoT (DNS-over-TLS) | 853 | TLS/TCP | TLS 1.3 | Port identifiable | Yes | Medium | 7858 |
| DoH (DNS-over-HTTPS) | 443 | HTTPS/TCP | TLS 1.3 | Indistinguishable from HTTPS | Yes | Medium | 8484 |
| DoH3 (DNS-over-HTTP/3) | 443 | QUIC/UDP | TLS 1.3 | Same as HTTPS | Yes | Low | 9250 |
| DoQ (DNS-over-QUIC) | 853/8853 | QUIC/UDP | TLS 1.3 | Identifiable | Yes | Lowest (encrypted) | 9250 |
| DNSCrypt | 443/5443 | UDP/TCP | X25519+XSalsa20 | Identifiable | Yes | Low | — |
For most scenarios, DoH is recommended: uses port 443, blending with normal HTTPS traffic so ISPs can't identify encrypted DNS by port. For ultra-low latency, use DoQ (QUIC has no TCP handshake). Enterprise networks should consider DoT — its dedicated port allows clean firewall policies.
Encrypted DNS Provider Comparison
| Provider | DoH URL | DoT Hostname | IP | Logging | Ad Filter | DNSSEC |
|---|---|---|---|---|---|---|
| Cloudflare | https://cloudflare-dns.com/dns-query | one.one.one.one | 1.1.1.1 / 1.0.0.1 | 24h purge | No (1.1.1.2 yes) | ✅ |
https://dns.google/dns-query | dns.google | 8.8.8.8 / 8.8.4.4 | 48h anonymized | No | ✅ | |
| Quad9 | https://dns.quad9.net/dns-query | dns.quad9.net | 9.9.9.9 / 149.112.112.112 | No logs | Malware | ✅ |
| NextDNS | https://dns.nextdns.io/YOUR_ID | YOUR_ID.dns.nextdns.io | Dynamic | Configurable | Highly custom | ✅ |
| AdGuard | https://dns.adguard-dns.com/dns-query | dns.adguard-dns.com | 94.140.14.14 | No logs | Ads+Trackers | ✅ |
| Mullvad | https://dns.mullvad.net/dns-query | dns.mullvad.net | 194.242.2.2 | No logs | Optional | ✅ |
| Ali DNS | https://dns.alidns.com/dns-query | dns.alidns.com | 223.5.5.5 / 223.6.6.6 | Undisclosed | No | ✅ |
| Tencent DNSPod | https://doh.pub/dns-query | dot.pub | 119.29.29.29 | Undisclosed | No | ✅ |
Operating System Setup
Windows 11 / 10 (DoH)
macOS (DoH / DoT)
Linux (systemd-resolved DoT)
Android (DoT Native)
iOS / iPadOS (DoH)
Browser DoH Setup
| Browser | Settings Path | Default DoH |
|---|---|---|
| Chrome | chrome://settings/security → Use secure DNS | System / Cloudflare / Google selectable |
| Firefox | about:preferences#privacy → DNS over HTTPS | Cloudflare (default on in US) |
| Edge | edge://settings/privacy → Secure DNS | Same as Chrome |
| Brave | brave://settings/security → Secure DNS | Quad9 |
| Safari | No browser-level DoH (requires system config) | — |
Browser-level DoH only protects DNS queries from the browser. Other apps (terminal, email clients) still use system DNS. For full protection, configure at system or router level.
Proxy Tool DNS Configuration
Clash / Clash Meta (mihomo)
V2Ray / Xray
sing-box
WireGuard
OpenVPN
Shadowsocks + dns2socks
TUN Mode Explained
TUN (network tunnel) mode creates a virtual network interface in the OS, capturing all network traffic (including DNS) and forwarding it to the proxy client. Unlike manual proxy configuration, TUN mode requires no per-app proxy setup — all traffic automatically goes through the tunnel.
TUN Flow
App → OS routing → TUN interface → Proxy client (Clash/sing-box) → Rule matching → Direct or proxy → Remote server
DNS Handling
In TUN mode, DNS queries are intercepted by dns-hijack and handled by the proxy's DNS module. fake-ip mode returns a fake IP, using the real domain when connecting.
fake-ip vs redir-host
fake-ip: Fast (no DNS delay), but some apps may not work (use fake-ip-filter). redir-host: Real DNS first then route, better compatibility but slower.
Stack Selection
system: OS stack, stable but needs root. gvisor: Userspace stack, no root but higher CPU. mixed: TCP=system, UDP=gvisor (recommended).
Clash TUN Full Config
sing-box TUN
iptables Transparent Proxy DNS Forwarding
On a Linux gateway/router, use iptables to forcefully redirect all DNS traffic to a local encrypted DNS proxy (clash, sing-box, or dnscrypt-proxy), preventing any device from bypassing encrypted DNS.
DNS Hijack (Redirect Port 53)
TPROXY Transparent Proxy (Full Traffic)
nftables (Modern Alternative)
Router-Level DNS Encryption
OpenWrt
Install https-dns-proxy → LuCI → Services → HTTPS DNS Proxy → Add Cloudflare/Google → Disable dnsmasq forwarding. Or install OpenClash/PassWall for integrated proxy+DNS.
Asus Merlin
Firmware 386+ natively supports DoT: Administration → System → DNS Privacy Protocol → DNS-over-TLS → Add servers. Or install stubby via Entware.
pfSense / OPNsense
Services → DNS Resolver (Unbound) → Custom Options → Add forward-tls-upstream: yes and DoT servers. OPNsense Unbound natively supports DoT.
MikroTik
RouterOS v6.47+ supports DoH: /ip dns set use-doh-server=https://cloudflare-dns.com/dns-query verify-doh-cert=yes. Import CA certificate first.
Split DNS Strategy
In proxy environments, split DNS is a critical optimization: domestic domains use domestic DNS (to avoid resolving to overseas CDN), foreign domains use overseas DNS (to avoid poisoning).
① Bootstrap DNS uses plain IP (e.g., 223.5.5.5) to avoid circular dependency resolving DNS server domains; ② fake-ip mode doesn't care about DNS poisoning since actual domains are resolved remotely through the proxy tunnel; ③ Enable geoip in fallback-filter to decide fallback based on the resolved IP's geographic location.
Security & Privacy Analysis
| Threat | Plain DNS | DNSSEC | DoT | DoH | DoQ |
|---|---|---|---|---|---|
| ISP snooping query content | ✗ | ✗ | ✓ | ✓ | ✓ |
| ISP identifying protocol | — | — | Port 853 | Blends with HTTPS | QUIC |
| DNS cache poisoning | ✗ | ✓ | ✓ | ✓ | ✓ |
| MITM tampering | ✗ | ✓ | ✓ | ✓ | ✓ |
| ISP blocking | — | — | Easy | Hard | Possible |
| Metadata leak (SNI/IP) | All | All | Server IP | SNI+IP | Server IP |
QUIC (HTTP/3) uses UDP port 443. Many TCP-only proxy tools (HTTP proxies, some SOCKS5) can't tunnel QUIC traffic, causing the browser to bypass the proxy and connect directly — leaking both IP and DNS. Prevention: ① Enable TUN mode to capture all UDP; ② Disable QUIC in browser (chrome://flags/#enable-quic → Disabled); ③ Use UDP-capable protocols (Shadowsocks/Trojan/VLESS+XUDP). Verify with our IP Leak Test QUIC channel.
DoH's HTTPS connection still exposes the DoH server domain via SNI during TLS handshake. ECH (formerly ESNI) encrypts the SNI field — combined with DoH, it makes DNS queries completely invisible. Chrome and Firefox have experimental ECH support.
FAQ
DoH uses port 443, indistinguishable from regular HTTPS, harder for ISPs/firewalls to identify and block. DoT uses dedicated port 853, which firewalls can specifically block. Personal users: DoH. Enterprise: DoT (easier to manage).
First query may add 5-20ms (TLS handshake), but subsequent queries benefit from HTTP/2 multiplexing and connection reuse, approaching Plain DNS latency. DoQ's QUIC 0-RTT handshake is even faster. Real-world difference is negligible.
① Apps connecting by IP directly (like Telegram) bypass DNS and can't be proxied by fake-ip; ② Local ping returns fake IPs, unusable for network debugging; ③ Requires maintaining a fake-ip-filter exclusion list (NTP servers, LAN discovery protocols).
① Use our DNS Leak Test tool; ② Check Cloudflare's https://1.1.1.1/help page — look for "Using DNS over HTTPS: Yes"; ③ Test with dig: dig @1.1.1.1 example.com +https (requires dig 9.18+).
Possible causes: ① Bootstrap DNS uses poisoned Plain DNS to resolve the DoH server domain — use IP address as bootstrap instead; ② Other apps bypass proxy and send DNS directly — enable TUN mode to capture all traffic; ③ IPv6 DNS isn't covered by proxy — disable IPv6 or configure IPv6 DNS in proxy.
TUN mode is simpler, cross-platform (Windows/macOS/Linux), proxy client handles routing automatically. iptables/TPROXY is more flexible and performant, but Linux-only and complex to configure. Routers/gateways: iptables. Personal devices: TUN.
① Deploy Unbound + DoT as recursive resolver on gateway; ② Force all port 53 traffic through gateway DNS via iptables; ③ Internal domains → internal DNS, external → encrypted DNS (split-horizon); ④ Enable DNSSEC validation; ⑤ Log retention for compliance.