How a Name Is Resolved: Stub, Recursive and Authoritative Servers and Caching
The path of a DNS lookup: stub resolvers, recursive resolvers and authoritative servers, recursive versus iterative queries, a full resolution captured packet by packet, QNAME minimization, TTLs counting down, negative caching, measured cache savings and serve-stale.
kvi5hnuCode Sprout team member16 min readOn this page
Article 49 showed that DNS data is spread across a tree of zones, each served by its own servers. Your laptop doesn't walk that tree itself, though. It asks one server, and that server does the walking and remembers what it learns. This article follows a lookup through the three kinds of DNS software, captures a full resolution in the lab, and measures how much caching saves.
Three kinds of DNS software
- A stub resolver is the small piece of code in every host, usually in the C library or an operating system service, that applications call through functions such as
getaddrinfo(). It doesn't know the tree. It sends each question to a configured server and waits for a complete answer. - A recursive resolver (also called a full-service resolver, or simply the DNS server your network gives you) accepts questions from stubs and finds the answers by querying authoritative servers, starting from the root if necessary. It caches everything it learns. Your ISP, your company, or a public DNS service runs one.
- An authoritative server holds zone data and answers only for its zones. It doesn't chase other servers for you. The root and TLD servers are authoritative servers.
In between, many networks have a forwarder: a resolver, often in a home router or dnsmasq, that doesn't resolve on its own but passes questions to an upstream recursive resolver and caches the answers. Many hosts also run a local caching stub, such as systemd-resolved on Linux (listening on 127.0.0.53), the DNS Client service on Windows, or mDNSResponder on macOS.
The stub's questions to its resolver traditionally travel unencrypted over UDP port 53, which this article and the lab use. Today, browsers and operating systems can also send them over DNS over TLS, DNS over HTTPS or DNS over QUIC, so that the network in between can't read or change them. Article 55 covers those.
How the stub is configured depends on the system. On Linux, /etc/nsswitch.conf decides which sources are tried for host names and in which order:
hosts: files dns
files is /etc/hosts, consulted first, then dns, using the servers in /etc/resolv.conf. glibc's stub (glibc is the GNU C library used by most Linux distributions) waits 5 seconds for a reply by default and tries each server twice (options timeout:5 attempts:2 in resolv.conf change this).
Recursive and iterative queries
The client's question to its resolver is a recursive query: it sets the RD (recursion desired) flag, meaning "give me the final answer". The resolver's questions to authoritative servers are iterative: each server answers from its own data or returns a referral, and the resolver follows it.

A server that offers recursion sets RA (recursion available) in its responses. Asking the lab resolver with recursion turned off (+norecurse) for a name it hasn't looked up returns no answer, only what it already has in its cache: the servers for example.com.
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 5
;; AUTHORITY SECTION:
example.com. 3558 IN NS ns2.example.com.
example.com. 3558 IN NS ns1.example.com.
;; ADDITIONAL SECTION:
ns1.example.com. 172758 IN A 198.51.100.53
ns2.example.com. 172758 IN A 198.51.100.54
ns1.example.com. 172758 IN AAAA 2001:db8:2::53
ns2.example.com. 172758 IN AAAA 2001:db8:2::54
;; Query time: 1 msec
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
The second query asked ns1, an authoritative server, to recurse. It answered for its own zone with aa, but without ra, and dig warned that recursion isn't available. Authoritative servers that also offer recursion to the whole Internet are open resolvers, which attackers abuse (article 54), so the two roles are usually kept on separate servers.
A full resolution, packet by packet
With a freshly started resolver, its cache empty, the client asked for www.example.com:
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; ANSWER SECTION:
www.example.com. 3600 IN A 198.51.100.10
;; Query time: 3 msec
A capture on the resolver shows everything it did to produce that answer:
IP 192.0.2.10.49781 > 198.51.100.99.53: 22423+ [1au] A? www.example.com. (44)
IP6 2001:db8:2::99.57876 > 2001:db8:2::201.53: 983 [1au] NS? . (40)
IP6 2001:db8:2::99.33414 > 2001:db8:2::201.53: 44727% [1au] NS? com. (44)
IP6 2001:db8:2::201.53 > 2001:db8:2::99.57876: 983*- 1/0/3 NS a.root.test. (124)
IP6 2001:db8:2::201.53 > 2001:db8:2::99.33414: 44727- 0/1/3 (129)
IP6 2001:db8:2::99.37355 > 2001:db8:2::201.53: 63437% [1au] NS? test. (61)
IP6 2001:db8:2::201.53 > 2001:db8:2::99.37355: 63437- 0/1/3 (126)
IP6 2001:db8:2::99.54166 > 2001:db8:2::202.53: 5202% [1au] NS? gtld.test. (50)
IP6 2001:db8:2::202.53 > 2001:db8:2::99.54166: 5202*- 0/1/1 (121)
IP6 2001:db8:2::99.41875 > 2001:db8:2::202.53: 37759% [1au] A? a.gtld.test. (68)
IP6 2001:db8:2::99.34598 > 2001:db8:2::202.53: 37419% [1au] AAAA? a.gtld.test. (68)
IP6 2001:db8:2::202.53 > 2001:db8:2::99.41875: 37759*- 1/1/2 A 198.51.100.202 (126)
IP6 2001:db8:2::202.53 > 2001:db8:2::99.34598: 37419*- 1/1/2 AAAA 2001:db8:2::202 (126)
IP6 2001:db8:2::99.48711 > 2001:db8:2::202.53: 5932% [1au] NS? example.com. (68)
IP6 2001:db8:2::202.53 > 2001:db8:2::99.48711: 5932- 0/2/5 (192)
IP6 2001:db8:2::99.45377 > 2001:db8:2::54.53: 10922% [1au] A? www.example.com. (56)
IP6 2001:db8:2::54.53 > 2001:db8:2::99.45377: 10922*- 1/2/5 A 198.51.100.10 (212)
IP 198.51.100.99.53 > 192.0.2.10.49781: 22423 1/0/1 A 198.51.100.10 (60)
In tcpdump's DNS notation, + in a query means RD is set, [1au] means one additional record (the EDNS OPT record, article 51), and % marks the CD (checking disabled) flag. In responses, * means authoritative, - means recursion isn't available, and 1/0/3 counts the answer, authority and additional records.
Step by step:
- The client's query arrived (
A? www.example.com., with+). - Priming. The resolver first asked the root server from its built-in hints for the current list of root servers (
NS? .). Real resolvers do this at startup so they don't rely on an outdated hints file (RFC 9609). - QNAME minimization. QNAME is the name in a query's question. Instead of sending the root the full name, the resolver asked only
NS? com., and later asked the TLD server only aboutexample.com.A root server has no need to know which host you want. This privacy feature is defined in RFC 9156 and is on by default in current BIND, Unbound, Knot Resolver and PowerDNS Recursor (the widely used open-source resolvers). - Along the way, the resolver also had to resolve the name of the TLD server,
a.gtld.test, because the glue arrived in a referral but the resolver wanted authoritative addresses. That's the detour throughtest.andgtld.test. - With the servers for
example.comknown, the resolver asked one of them for the full name, and got an authoritative answer (*). - Finally, it answered the client.
One client question cost 8 queries upstream. Most of them were about the infrastructure: root, TLD and name server addresses, which are now cached for days.
The same question, a second time
;; ANSWER SECTION:
www.example.com. 3596 IN A 198.51.100.10
;; Query time: 1 msec
IP 192.0.2.10.60985 > 198.51.100.99.53: 41498+ [1au] A? www.example.com. (44)
IP 198.51.100.99.53 > 192.0.2.10.60985: 41498 1/0/1 A 198.51.100.10 (60)
Only the client's query and the answer appear. The resolver answered from its cache, and the TTL shows that 4 seconds had passed since it cached the record.
Caching and TTLs
Every resource record has a time to live (TTL): the number of seconds it may be kept in a cache. A resolver that answers from its cache returns the remaining TTL, so the value counts down. The lab's short.example.com has a TTL of 30 seconds, queried every 10 seconds:
short.example.com. 30 IN A 198.51.100.30
short.example.com. 20 IN A 198.51.100.30
short.example.com. 10 IN A 198.51.100.30
short.example.com. 30 IN A 198.51.100.30
After 30 seconds, the record expired, the resolver fetched it again, and the TTL started over at 30. Zone administrators choose TTLs as a trade-off:
- Long TTLs (hours to a day) mean fewer queries, faster lookups and resilience if a zone's authoritative servers are briefly unreachable.
- Short TTLs (seconds to minutes) mean changes take effect quickly. Load balancers and failover services use them.
- Before a planned change, such as moving a website to a new address, administrators lower the TTL a day or so in advance, make the change, then raise it again. Otherwise old answers stay in caches for up to the old TTL.
Resolvers also cap TTLs. BIND's defaults are 1 week for positive answers (max-cache-ttl) and 3 hours for negative ones (max-ncache-ttl), and RFC 8767 recommends a 7-day maximum. Some resolvers also impose a minimum, which violates the zone owner's intent and is discouraged.
Measuring what the cache saves
To make the effect visible, the lab added one-way delays to the links: 40 ms to the root server, 25 ms to the TLD server, 15 ms to each zone server and 5 ms to the client. Then the client looked up names in example.net, whose TLD and zone the resolver hadn't seen yet:
example.net, with net and example.net not cached yet: 92 ms
example.net again (answer cached): 8 ms
mail.example.net (zone's servers cached): 39 ms

The first lookup paid for every level. A different name in the same zone needed only the zone's servers. A repeated name cost only the trip to the resolver. On the real Internet, most lookups hit the cache: large resolvers answer the great majority of queries without contacting any authoritative server.
Negative caching
Answers that say "no" are cached too. There are two kinds:
- NXDOMAIN: the name doesn't exist at all.
- NODATA: the name exists but has no record of the requested type. It's a
NOERRORresponse with an empty answer section.
Both carry the zone's SOA record in their authority section, and the negative answer may be cached for the smaller of the SOA record's own TTL and its last field, MINIMUM, as RFC 2308 specifies. In the lab zone, both are 300 seconds. The SOA's data fields are the primary server, the administrator's mailbox (with the first dot standing for @), then five numbers: the serial, refresh, retry and expire timers, and MINIMUM, the last one (article 52 explains each):
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 25711
;; AUTHORITY SECTION:
example.com. 300 IN SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300
;; Query time: 0 msec
example.com. 295 IN SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300
The second query, 5 seconds later, came from the cache, with the SOA's TTL counting down from 300 to 295. A www.example.com MX query (MX records name a domain's mail servers) shows NODATA: no error, no answers, one authority record (the SOA):
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3497
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
Negative caching matters because many queries are for names that don't exist: typos, search-list expansions, and software probing for optional names. RFC 9520 (2023) extends caching to resolution failures, such as timeouts and SERVFAIL (the status a resolver returns when it couldn't get an answer at all): resolvers must remember a failure for at least 1 second and at most 5 minutes, so that a broken zone isn't hammered with retries.
When a zone's servers are unreachable: serve-stale
What should a resolver do if a cached record expires while every authoritative server for its zone is down? Strictly, it should fail. Serve-stale (RFC 8767) allows it to return the expired data instead, with a short TTL, when it can't refresh it. This kept many sites reachable during large DNS provider outages.
In the lab, the resolver was configured to serve stale data. The client looked up short.example.com, then both zone servers were disconnected and the 30-second TTL was allowed to pass:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3200
; EDE: 3 (Stale Answer): (stale data prioritized over lookup)
;; ANSWER SECTION:
short.example.com. 30 IN A 198.51.100.30
;; Query time: 8 msec
The answer came back anyway, with an Extended DNS Error (EDE, RFC 8914) code 3, "Stale Answer", telling the client that the data was expired. BIND gives stale answers a 30-second TTL by default and keeps stale data for up to max-stale-ttl (1 hour in this lab). Unbound, Knot Resolver and the large public resolvers implement serve-stale too.
Caches outside the resolver
Answers are cached at several layers, which is why "I changed the DNS record but my computer still goes to the old address" is so common:
- Browsers keep their own short DNS cache, typically about a minute.
- The operating system's stub:
systemd-resolved(resolvectl flush-caches), the Windows DNS Client service (ipconfig /displaydnsandipconfig /flushdns; registry valuesMaxCacheTtlandMaxNegativeCacheTtlunderHKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameterscap the times), and macOS'smDNSResponder(sudo killall -HUP mDNSResponder). The older Linuxnscddaemon also caches but is rarely used for DNS now. - Home routers and forwarders such as
dnsmasq. - The recursive resolver.
- Applications such as Java, which caches successful lookups for 30 seconds by default (
networkaddress.cache.ttl; the security manager, which used to make it cache forever, was permanently disabled in JDK 24), and some HTTP clients and connection pools, which keep using an address for as long as a connection is open.
Flushing your own caches doesn't flush your ISP's resolver: only the TTL does that.
Common questions
What's the difference between a recursive resolver and an authoritative server?
A recursive resolver answers any question for its clients by querying other servers and caching the results. An authoritative server answers only about the zones it holds, from its own data, and never queries others for you. One BIND or Knot instance can do either job, but they're normally kept separate.
Why does the resolver ask the root for com. instead of the full name?
That's QNAME minimization (RFC 9156). Each server needs to know only enough to give the next referral, so sending the full name to the root and TLD servers would leak which host you're visiting for no benefit. Some broken servers mishandle minimized queries, so resolvers use a relaxed mode that falls back to the full name when that happens.
If the root servers went down, would the Internet stop working?
Not immediately. Resolvers cache the TLD delegations for two days, so lookups would keep working for most names until those entries expired. The root servers are also anycast at about 2,000 sites, which makes a complete outage very unlikely. Some resolvers go further and keep a local copy of the whole root zone (RFC 8806).
How long until everyone sees my DNS change?
Up to the old record's TTL, plus any extra time from caches that cap or ignore TTLs, such as browsers and long-lived connections. Lowering the TTL well before the change, by at least the old TTL, shortens that window. "Propagation" is really just cache expiry: authoritative servers have the new data almost immediately.
What does NXDOMAIN mean compared to NOERROR with no answer?
NXDOMAIN means the name doesn't exist with any type. NOERROR with an empty answer (NODATA) means the name exists but has no record of the type you asked for, for example a name with an A record but no AAAA record. Both are cached according to the zone's SOA.
Why does my laptop's first lookup take longer than later ones?
The first lookup may need to fill several caches: the OS stub, a home router, the recursive resolver, each possibly asking the next. Later lookups for the same name stop at the first cache that has it. The lab showed about 90 ms for an uncached lookup and under 10 ms for a cached one.
Should I run my own recursive resolver?
Many networks do, for privacy (your queries don't go to a third party), control (local zones, filtering) or performance. It must be restricted to your own clients, though: an open resolver will be found and used in amplification attacks within days.
How do I find out which resolver my machine actually uses?
On Linux, /etc/resolv.conf lists the configured servers, but if it says nameserver 127.0.0.53, that's the local systemd-resolved stub, and resolvectl status shows the upstream servers it forwards to, per interface. On Windows, ipconfig /all or Get-DnsClientServerAddress shows them, and on macOS scutil --dns. The SERVER: line at the end of dig output (article 56) confirms who answered a particular query.
Summary
- Stub resolvers send recursive queries (RD set) to a recursive resolver, which does iterative queries to authoritative servers, following referrals from the root down, and caches everything it learns.
- Authoritative servers answer only for their own zones, with the AA flag; recursive resolvers set RA.
- The lab's cold-cache resolution needed 8 upstream queries, including root priming and the TLD server's own address. QNAME minimization sent each server only the part of the name it needed.
- A cached answer's TTL counts down. Short TTLs speed up changes; long TTLs reduce load and latency. Lower TTLs before planned changes.
- In the lab, a lookup with nothing cached took about 90 ms, with the zone's servers cached about 40 ms, and with the answer cached under 10 ms.
- NXDOMAIN and NODATA are cached for the minimum of the SOA's TTL and its MINIMUM field (RFC 2308). Resolution failures are cached for 1 second to 5 minutes (RFC 9520).
- Serve-stale (RFC 8767) returns expired data when no authoritative server can be reached, flagged with Extended DNS Error 3.
- Browsers, operating systems, routers and applications keep their own caches, which explains many "DNS still shows the old address" problems.
Practice questions
1. A client's resolver has nothing cached. How many authoritative servers, at a minimum, must it contact to resolve www.example.com, assuming referrals include glue?
Answer
Three: a root server (referral to com), a com server (referral to example.com), and an example.com server (the answer). In practice there are often more, as the lab showed, for priming the root server list and resolving name server names whose glue isn't trusted or isn't supplied.
2. A record has a TTL of 3,600. A resolver cached it 1,000 seconds ago. What TTL does the resolver return to a client, and how long may the client cache it?
Answer
2,600 seconds, the remaining time. The client may cache it for those 2,600 seconds, so the record never outlives the original 3,600-second limit, counted from when the resolver received it.
3. A zone's SOA record has TTL 3,600 and MINIMUM 300. For how long may a resolver cache an NXDOMAIN answer for a name in that zone?
Answer
300 seconds, the smaller of the SOA record's TTL and its MINIMUM field, as RFC 2308 specifies.
4. You plan to move www.example.com to a new address on Friday. Its TTL is 86,400 (one day). What should you do, and when?
Answer
At least a day before the move, so by Thursday, lower the TTL to something short, such as 300 seconds, so caches pick up the short TTL. On Friday, change the address; caches expire within 5 minutes. After the move is confirmed, raise the TTL again.
5. A query to your company's authoritative server, with RD set, returns an answer for your own zone with aa but a warning "recursion requested but not available". Is the server misconfigured?
Answer
No. That's the correct behavior for an authoritative-only server: it answers authoritatively for its zones and refuses to recurse for others. Offering recursion to everyone from an authoritative server would make it an open resolver.
6. Both authoritative servers for a zone fail at 10. A record in it had 20 minutes left in a resolver's cache. What happens at 10 with and without serve-stale?
Answer
Without serve-stale, the record expires at 10, the resolver can't refresh it, and clients get SERVFAIL. With serve-stale (RFC 8767), the resolver keeps answering with the expired record, using a short TTL and Extended DNS Error 3 (Stale Answer), until the servers come back or its maximum stale time runs out.
7. Why does a resolver's second lookup in a new TLD usually cost one upstream query, while the first cost several?
Answer
The first lookup had to learn the TLD's servers from the root, then the zone's servers from the TLD, and possibly server addresses. Those referrals are cached with long TTLs, often two days for TLD delegations. A second lookup in the same zone goes directly to the zone's servers.
Previous: The DNS Name Space: Names, Labels, Zones and Delegation
Next: Inside a DNS Message: Header, Sections, EDNS(0) and UDP Versus TCP

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.