Encrypted DNS: DNS over TLS, HTTPS and QUIC
Why classic DNS leaks your browsing and how encryption fixes it: DNS over TLS on port 853, DNS over HTTPS with its URL and media type, DNS over QUIC, padding, discovering encrypted resolvers with DDR and DNR, the measured cost of the handshake, and what encryption does and doesn't protect.
kvi5hnuCode Sprout team member14 min readOn this page
Everything in the previous DNS articles traveled in clear text over UDP or TCP port 53, sometimes called Do53. Anyone on the path, such as the Wi-Fi operator, the ISP (Internet service provider) or an attacker on the LAN, can read every name you look up and can change the answers. Article 54 showed how hard blind forgery has become, but an on-path attacker doesn't need to guess anything: they see the query and answer it first.
Since 2016, the IETF (Internet Engineering Task Force, the body that writes Internet standards, article 5) has standardized several ways to encrypt the connection between a stub and its recursive resolver, and more recently between resolvers and authoritative servers. This article runs DNS over TLS and DNS over HTTPS on the lab resolver, compares them with Do53, and covers how clients find encrypted resolvers automatically.
What plain DNS reveals
The lab resolver was configured to serve DNS on three ports: plain DNS on 53, DNS over TLS on 853 and DNS over HTTPS on 443, using the built-in TLS support of BIND, the DNS server software the lab runs, with a self-signed certificate. TLS (Transport Layer Security, article 83) is the protocol that encrypts and authenticates HTTPS connections; here it does the same for DNS. The listening sockets:
tcp 198.51.100.99:443
tcp 198.51.100.99:53
tcp 198.51.100.99:853
tcp [2001:db8:2::99]:53
udp 198.51.100.99:53
udp [2001:db8:2::99]:53
A plain query, captured on the client:
198.51.100.10
IP 192.0.2.10.34016 > 198.51.100.99.53: 65083+ [1au] A? www.example.com. (44)
IP 198.51.100.99.53 > 192.0.2.10.34016: 65083 1/0/1 A 198.51.100.10 (60)
bytes 'example' visible in the capture: 2
In the tcpdump lines, 65083 is the query ID, A? is the question, and 1/0/1 counts answer, authority and additional records (article 51). The name www.example.com and the answer are readable in the capture, and the count shows the text "example" appears twice in the raw bytes, once in the query and once in the response. That's the privacy problem in miniature. DNS queries reveal which sites you visit, which apps you use, and when, and they're also easy to tamper with, for example to block or redirect sites.
The diagram below compares the four ways of carrying the same DNS message; the rest of the article goes through them one by one.

DNS over TLS (DoT)
DNS over TLS (RFC 7858, 2016) is the simplest design: open a TCP connection to port 853, do a TLS handshake, and then send DNS messages exactly as over plain TCP, each with its 2-byte length prefix (article 51). The same query, over TLS, followed by a summary of the capture:
www.example.com. 3595 IN A 198.51.100.10
;; SERVER: 198.51.100.99#853(198.51.100.99) (TLS)
packets in the DoT exchange: 16
192.0.2.10 ClientHello
198.51.100.99 ServerHello
bytes 'example' visible in the capture: 0
The capture now holds a TCP handshake, a TLS ClientHello and ServerHello, and encrypted records, and the name doesn't appear anywhere in it.
The DoT client in the lab used opportunistic mode: it encrypted the connection but didn't check the server's certificate, so it's protected against passive eavesdropping but not against an active attacker who intercepts the connection. RFC 8310 defines a strict mode, where the client authenticates the resolver, by its name in a certificate (for example dns.example.net) or a pinned key. Android's Private DNS setting, available since Android 9, uses strict DoT with a host name the user enters.
Because DoT has its own port, networks can recognize and block it easily. That's useful for enterprises that want to keep DNS under control, and frustrating for users on networks that censor DNS.
DNS over HTTPS (DoH)
DNS over HTTPS (RFC 8484, 2018) carries each DNS message in an HTTP request to a URL such as https://dns.example.net/dns-query. Two forms:
- GET, with the DNS message encoded in base64url (base64 using only URL-safe characters, without the trailing
=padding) in thednsparameter. This form can be cached by HTTP caches. - POST, with the raw DNS message as the request body.
Both use the media type application/dns-message. In the lab, the client built a query by hand, encoded it and fetched it with curl over HTTP/2:
GET /dns-query?dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB
HTTP/2 200
content-type: application/dns-message
content-length: 49
cache-control: max-age=3592
body: 49 bytes of binary DNS message, ID 0, flags 0x8180, answer address 198.51.100.10
The response is an ordinary HTTP/2 response, with the binary DNS message as its body. Two details stand out:
- The query ID was 0. RFC 8484 recommends ID 0 for DoH, because HTTP already matches requests to responses, and a constant ID makes identical GET requests cacheable.
- The server set
cache-control: max-ageto the remaining TTL of the answer, so HTTP caches don't keep it longer than DNS would.
dig can do DoH too:
www.example.com. 3592 IN A 198.51.100.10
;; SERVER: 198.51.100.99#443(198.51.100.99) (HTTPS)
DoH runs on port 443 and looks like any other HTTPS traffic, so networks can't easily single it out; blocking it means blocking the resolver's address. That's why browsers adopted it: Firefox enabled DoH by default for users in the United States in 2020, Chrome and Edge upgrade to DoH automatically when the system resolver is a known DoH provider, and Windows 11 and Apple's systems support DoH and DoT as system resolvers. It also works over HTTP/3, on QUIC, the UDP-based encrypted transport covered in article 86.
The flip side is that DoH lets applications bypass the operating system's and the network's DNS settings. An enterprise that relies on internal names or DNS filtering may find that a browser sends queries elsewhere. Firefox, for example, checks for a special canary domain (a test name that a network can make fail on purpose to say "don't use DoH here") and for enterprise policies before enabling DoH, and turns it off if the network signals that it shouldn't be used.
DNS over QUIC (DoQ)
DNS over QUIC (RFC 9250, 2022) carries each query and response on its own QUIC stream over UDP port 853. QUIC (article 86) combines the transport and TLS 1.3 handshakes, avoids head-of-line blocking between queries (one lost packet no longer delays the answers to other queries, as it does on a single TCP stream), survives address changes, and can resume with 0-RTT data (data sent in the very first packet, without waiting a round trip). DoQ is intended for stub-to-resolver traffic as well as for zone transfers and resolver-to-authoritative traffic. Several public resolvers and AdGuard, Knot Resolver and other implementations support it. BIND, which runs the lab, doesn't serve DoQ yet, so it isn't shown here.
The cost of the handshake
Encryption costs a TCP handshake and a TLS handshake before the first query can be sent. With 20 ms added to the round trip between client and resolver, and all answers cached in the resolver:
Do53 over UDP, one query: 25 ms
DoT, new connection, one query: 78 ms
DoH, new connection, one query: 75 ms
DoT, one connection, 10 queries: 327 ms in total, 32 ms per query

A new encrypted connection cost about three round trips more than a UDP query: TCP's handshake, TLS 1.3's handshake and then the query. Once the connection was open, queries cost about one round trip each, close to Do53. That's why encrypted DNS clients keep connections open, use TLS session resumption, and send many queries over one connection. DoQ with 0-RTT can remove most of the remaining handshake cost.
Padding: hiding message sizes
Encryption hides content, but not length. DNS messages are small and their sizes vary with the name, so an observer can sometimes guess the name from the size of the encrypted message. The EDNS(0) Padding option (RFC 7830) lets a client or server add filler bytes, and RFC 8467 recommends padding queries to a multiple of 128 bytes and responses to a multiple of 468. The lab resolver pads responses when the client asks for padding:
+notcp: response 60 bytes
+tls: response 468 bytes
Over UDP, the response was its natural 60 bytes, because padding plain DNS is pointless. Over TLS, it was padded to exactly 468 bytes.
Finding an encrypted resolver
A client learns its resolver's address from DHCP or router advertisements (articles 29 to 32), but that only says "use 198.51.100.99 on port 53". Two mechanisms tell clients that the same resolver also speaks DoT, DoH or DoQ:
- DDR, Discovery of Designated Resolvers (RFC 9462): the client queries its resolver for the special name
_dns.resolver.arpawith type SVCB (article 52). The resolver answers with SVCB records describing its encrypted endpoints. The client then connects and checks that the resolver's certificate includes the original IP address, so an attacker can't redirect it. - DNR, Discovery of Network-designated Resolvers (RFC 9463): new DHCP, DHCPv6 and router advertisement options that carry the encrypted resolver's name, address and parameters directly.
The lab resolver serves a resolver.arpa zone advertising its DoT and DoH endpoints:
_dns.resolver.arpa. 300 IN SVCB 1 res.example.com. alpn="dot" port=853 ipv4hint=198.51.100.99
_dns.resolver.arpa. 300 IN SVCB 2 res.example.com. alpn="h2" ipv4hint=198.51.100.99 key7="/dns-query{?dns}"
The first record offers DoT on port 853. The second offers DoH over HTTP/2, with the URL template in the dohpath parameter, which this version of dig shows by its number, key7. Apple's systems use DDR to upgrade automatically when their configured resolver supports it, and Windows 11 can do the same once DDR is turned on in its DoH settings.
Encryption beyond the stub
Stub-to-resolver encryption protects the most identifying hop, but resolvers also talk to authoritative servers in the clear:
- Resolver to authoritative encryption is being deployed experimentally. RFC 9539 describes opportunistic, unauthenticated DoT or DoQ from resolvers to authoritative servers that support it.
- Zone transfers can use TLS (XoT, XFR over TLS, RFC 9103, article 53).
- Oblivious DoH (ODoH, RFC 9230, experimental) adds a proxy between client and resolver: the proxy sees the client's address but not the query, and the resolver sees the query but not the client. Apple's iCloud Private Relay uses a similar split.
- QNAME minimization (article 50) reduces what each authoritative server learns.
What encryption doesn't do
- It doesn't authenticate the data. DoT and DoH protect the channel to your resolver. If the resolver itself is compromised, or lies, encryption doesn't help. DNSSEC (article 84) authenticates the data from the zone owner, so the two are complementary.
- It moves trust, not removes it. The resolver still sees every query. Choosing an encrypted resolver means trusting its operator's logging and privacy policy.
- The site name may still leak elsewhere: in the TLS Server Name Indication of the connection that follows, unless Encrypted Client Hello (ECH, RFC 9849) is used (article 83), and in the destination IP address.
- Enterprise controls based on watching or rewriting DNS stop working when clients encrypt to outside resolvers. Organizations respond by running their own encrypted resolvers, advertising them with DDR or DNR, and using policies to stop applications from choosing others.
Common questions
Should I use DoT or DoH?
For privacy from the network, both are equivalent: they encrypt the same messages with TLS. DoT is simpler and easier for networks to manage, which suits operating systems and routers. DoH blends in with web traffic and integrates with HTTP libraries, which suits browsers and apps. Many clients support both, and DoQ where available.
Does encrypted DNS make me anonymous?
No. It hides your queries from the network path, but the resolver sees them, the sites you connect to see your address, and the destination IP addresses are visible. For anonymity, you need tools like Tor; encrypted DNS just removes one easy leak.
Is DoH slower than normal DNS?
The first query on a new connection is slower, about three extra round trips in the lab. After that, queries on the same connection cost about as much as Do53. Clients keep connections open, so in normal use the difference is small, and nearby anycast resolvers keep round trips short.
Why does my company block DoH?
Because it bypasses internal DNS: internal names stop resolving, security filtering based on DNS stops working, and logs used for incident response go missing. Enterprises typically block known public DoH servers, disable DoH in browsers by policy, and provide their own encrypted resolver.
How does a client know a DoT server is the right one?
In strict mode, by checking its TLS certificate against a name the user or network configured, for example dns.example.net. With DDR, the certificate must also include the IP address of the original unencrypted resolver. In opportunistic mode, it doesn't check, and only gets protection from passive eavesdroppers.
What port does DNS over QUIC use?
UDP port 853. DoT uses TCP port 853, and DoH uses 443, over TCP for HTTP/2 or UDP for HTTP/3.
Summary
- Plain DNS on port 53 exposes every query and answer to the network path and lets on-path attackers change answers.
- DoT (RFC 7858) sends normal DNS over TLS on TCP port 853. It's easy to deploy and easy for networks to identify.
- DoH (RFC 8484) carries DNS messages in HTTPS requests, by GET with a base64url
dnsparameter or by POST, with the media typeapplication/dns-message, usually with query ID 0. It looks like ordinary HTTPS on port 443. - DoQ (RFC 9250) uses QUIC streams on UDP port 853, with faster handshakes and no head-of-line blocking.
- In the lab, a new encrypted connection cost about three extra round trips; reused connections were nearly as fast as Do53.
- EDNS padding (RFC 7830, RFC 8467) hides message sizes: queries to 128-byte blocks, responses to 468.
- DDR (RFC 9462) discovers a resolver's encrypted endpoints through SVCB records for
_dns.resolver.arpa. DNR (RFC 9463) delivers them in DHCP and router advertisements. - Encryption protects the channel, not the data: the resolver still sees everything, and DNSSEC is needed to authenticate answers.
Practice questions
1. A user on public Wi-Fi uses DoT in opportunistic mode. Which attacker does this protect against, and which not?
Answer
It protects against a passive eavesdropper who only records traffic, since queries are encrypted. It doesn't protect against an active attacker who intercepts the TCP connection and presents their own certificate, because opportunistic mode doesn't verify the server. Strict mode, which authenticates the resolver's certificate, protects against both.
2. Write the DoH GET request line for a DNS message whose base64url encoding is AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB, sent to a server whose URL template is https://dns.example.net/dns-query{?dns}.
Answer
GET /dns-query?dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB with Host: dns.example.net and Accept: application/dns-message, over HTTPS.
3. Why do DoH clients usually set the DNS query ID to 0?
Answer
HTTP already matches each response to its request, so the ID isn't needed. Using a constant 0 makes identical GET requests produce identical URLs, so HTTP caches can serve them. RFC 8484 recommends it.
4. With a 30 ms round trip to a resolver, roughly how long does the first DoT query take compared with the tenth query on the same connection, assuming TLS 1.3 and cached answers?
Answer
The first takes about 3 round trips, around 90 ms: one for the TCP handshake, one for the TLS 1.3 handshake and one for the query and answer. The tenth takes about one round trip, around 30 ms. Session resumption and TCP Fast Open or QUIC 0-RTT can reduce the first one.
5. A laptop's DHCP-assigned resolver is 192.0.2.53. How can the laptop learn that the same resolver also offers DoH, and how does it make sure an attacker isn't redirecting it?
Answer
With DDR, it queries _dns.resolver.arpa type SVCB at 192.0.2.53 and receives SVCB records for the encrypted endpoints, including the alpn and dohpath. It connects to the advertised endpoint and requires that the TLS certificate include 192.0.2.53 as an IP address, proving the encrypted server is designated by the original resolver. Alternatively, with DNR, the DHCP server provides the details directly.
6. A site is reached over DoH-resolved addresses, and the connection uses TLS without Encrypted Client Hello. Can a network observer still tell which site the user visits?
Answer
Usually yes. The TLS ClientHello's Server Name Indication contains the site name in clear text, and the destination IP address may identify the site. Encrypted DNS removes only the DNS leak; ECH closes the SNI leak.
Previous: DNS in Practice: Round Robin, Split DNS, Open Resolvers, mDNS, LLMNR and DNS Attacks
Next: Troubleshooting DNS With dig: Following a Resolution Step by Step

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.