DNS Recursion: Query Flow, Caching, and Troubleshooting

A laptop connects through a central server to several network servers.

Written by

in

DNS recursion is the job your resolver does when it takes one question from your device, chases the answer through the DNS hierarchy, and hands back a single final reply. With DNS recursion, a recursive resolver queries the root, TLD, and authoritative servers on your behalf, caches what it learns for each record’s TTL, and returns one answer (or one error) to your client. Your laptop asks once; the resolver does the walking.

A laptop connects through a central server to several network servers.

That single delegation is why the Domain Name System (DNS) feels instant most of the time, and why it confuses you when it breaks. A stale cache entry, a forwarder that times out, or a cached “this name does not exist” can make two machines on the same network disagree about the same hostname.

At PacketTools, the diagnostics come from production networks, where knowing which server answered and why decides whether you fix a record, flush a cache, or leave DNS alone. Once you can read the query flow and the header flags, you can place a failure at the client, the resolver, or the authoritative zone before you change anything.

How Does a Resolver Complete a DNS Lookup?

A resolver completes a lookup by checking its cache, then following referrals down the DNS hierarchy until an authoritative server returns a record or a definitive error. Your client sends a name, a type, and a class; the recursive DNS server turns that into a series of targeted questions and returns one DNS response.

What Does the Client Ask the Recursive Resolver to Do?

Your operating system runs a stub resolver: a small client that asks one configured DNS resolver and waits. Every DNS query it sends carries three things, which Microsoft lists as a fully qualified domain name, a query type, and a class (almost always IN for Internet).

The query also sets the RD (Recursion Desired) bit. That bit is the instruction: “resolve this completely and don’t send me referrals.” The stub resolver itself never walks the tree; on Windows, the DNS Client service does not perform recursion at all, so everything beyond your local cache and hosts file depends on the resolver you point at.

Before anything leaves your machine, the stub checks its own cache. On Windows, that cache holds entries from the hosts file plus answers from earlier queries, each kept for its TTL.

Following Referrals From Root to TLD to Authoritative Servers

On a cache miss, the recursive DNS service starts at the top of the DNS hierarchy. For www.example.com, the sequence looks like this:

  1. The resolver asks a root server, located through its built-in root hints.
  2. The root replies with a referral: NS records for the .com top-level domain (TLD).
  3. The resolver asks a TLD server, which refers it to the nameservers for example.com.
  4. The resolver asks those authoritative servers for the A record and gets an IP address.
  5. The resolver caches the answer for the record’s TTL and returns it to the client.

Each referral is itself cached. That’s why the second lookup for anything under .com skips the root entirely. When a parent zone’s NS records point to dead or wrong servers, the chain breaks at that step, which is the classic DNS delegation failure.

Returning an Answer, Following a CNAME, or Reporting an Error

The final step produces one of a few outcomes. A direct match returns the record with NOERROR. A CNAME sends the resolver back out to resolve the target name, which may live in an entirely different zone with its own delegation chain, so one hostname can trigger two full walks.

If the name doesn’t exist, the authoritative server returns NXDOMAIN. If the name exists but lacks the requested type, you get NOERROR with an empty answer (NODATA). If the resolver can’t reach any authority or validation fails, it returns SERVFAIL. Whatever comes back, the domain name resolution ends with one DNS response to your client, and the resolver remembers both successes and failures.

How Do Query Types and Server Roles Differ?

Query mode decides who follows the referrals, and server role decides who owns the data. A recursive query pushes the walking onto the server; an iterative query keeps it with the asker. An authoritative DNS server holds zone records, while a recursive server only borrows and caches them.

Recursive vs. Iterative Queries: Who Follows the Referrals?

“Recursive” is a request flag plus a server capability, so the same server can answer both ways. Two header bits define it:

Flag Set by Meaning
RD (Recursion Desired) Client, in the query “Resolve this fully for me.”
RA (Recursion Available) Server, in the response “I offer recursion to you.”
AA (Authoritative Answer) Server, in the response “This answer comes from my own zone data.”

Iteration happens in two cases, per Microsoft’s documentation: the client requests recursion but the server has it disabled, or the client doesn’t request recursion at all. The server then returns its best local answer, usually a referral listing NS and A records for servers closer to the name.

In practice, your stub sends recursive queries, and your resolver sends iterative ones to root, TLD, and authoritative servers. You only see raw iteration when you run tools like dig +trace or dig +norecurse.

Authoritative vs. Recursive Servers: Who Holds the Records?

An authoritative DNS server answers from zone files it hosts, sets the AA flag, and never chases other servers. A recursive DNS server holds no zones of its own for the names it resolves; it fetches records from authorities and caches them.

Authoritative Recursive
Data source Local zone Cache plus upstream lookups
AA flag Set Not set on cached answers
RA flag Normally off On for allowed clients
Who queries it Resolvers Stub clients

When you edit a record at your host, you’re changing authoritative data. Resolvers holding the old copy keep serving it until the TTL runs out. Combining both roles on one public-facing server is discouraged because each role faces different threats; split them when you can. Knowing the DNS record types each authority publishes helps you check the right data when answers look wrong.

How Do Forwarders and Public Resolvers Fit Into the Query Path?

A forwarder adds a hop. Your internal DNS server, often a Windows domain controller, hands unresolved queries to an upstream server instead of walking from the root. That upstream might be your ISP’s resolver or a public DNS server.

This matters for diagnosis because the forwarding server’s cache, the upstream’s cache, and your stub cache all sit in the path. A wrong answer may originate two hops away. Forwarders also concentrate failure: if the upstream is unreachable and root hints fallback is disabled, every external lookup fails at once, which shows up as a DNS server not responding on clients even though your local server is up.

How Does Caching Change Answers and Lookup Time?

A user’s computer connects through a DNS resolver to a nearby cache and remote servers.

Caching turns most DNS queries into a single fast round trip to your resolver, and it is also the reason different users see different answers after a change. Positive answers live for the record’s TTL, negative answers live for a value drawn from the zone’s SOA record, and every resolver keeps its own independent timers.

Cache Hits, Cache Misses, and TTL Expiry

A cache hit means the resolver already holds a valid answer and returns it immediately. A miss sends it back up the hierarchy. Each entry is keyed by name, type, and class, so example.com A and example.com AAAA expire separately.

A TTL is a ceiling on reuse: a resolver may drop a record early but isn’t allowed to keep it longer. On Windows DNS zones, the default minimum TTL is 3,600 seconds (one hour) unless you set per-record values.

Practical tip: lower a record’s TTL a full old-TTL period before a migration. If the record carries 86,400 seconds, cutting it to 300 an hour before the move does nothing for resolvers that cached it yesterday.

Caches also stack. Your browser, OS stub, local DNS server, and upstream forwarder each hold copies, so when you flush DNS cache on one layer, the next layer can hand the stale answer right back.

Negative Caching and Why DNS Changes Appear Inconsistent

Resolvers cache “no” answers too. An NXDOMAIN is cached against the whole name; NODATA is cached against the name and the specific type. The lifetime comes from the SOA record attached to the negative response, using the lower of the SOA’s own TTL and its minimum field.

This produces a common trap: someone queries a hostname before you create it, the resolver caches NXDOMAIN, and that resolver keeps saying the name doesn’t exist after you publish it. RFC 2308 recommends resolvers cap negative caching locally, suggesting one to three hours as a sensible default.

So when one office reaches the new server and another gets a DNS_PROBE_FINISHED_NXDOMAIN error, check which resolver each site uses before suspecting the zone.

Separating Resolver Lookup Time From Network Latency

A slow page load has at least two DNS-related components: the round trip from you to the resolver, and the resolver’s own upstream work on a miss. A cached answer from a nearby resolver often returns in a few milliseconds; a cold lookup adds the root, TLD, and authoritative round trips on top.

To separate them, run the same dig query twice and compare the Query time line. A slow first query and a fast second one point to upstream resolution. Two equally slow queries point to the path between you and the resolver, which is a network latency problem. Ping the resolver’s IP to confirm, and compare your result against general internet latency to that region. A DNS benchmark across several resolvers shows whether switching would help at all.

How Can You Test an Authorized Resolver?

A network professional checks DNS request paths on a computer beside server equipment.

You test a resolver by sending controlled queries with dig, reading the header flags, and comparing recursive and nonrecursive responses, but only against resolvers you run or have explicit permission to assess. Probing third-party servers can violate policy, and repeated queries add load to production systems.

Request Recursion With dig and Interpret RD, RA, and AA Flags

dig sets RD by default, so a plain query is a recursion request:

dig @10.0.0.53 www.example.com A

Read the flags: line in the header:

  • qr rd ra: the server accepted recursion and answered. Normal for your resolver.
  • qr rd with status REFUSED: you asked, and the server declined. On BIND, a denial commonly returns REFUSED without ra and may include a “Prohibited” Extended DNS Error.
  • qr aa: the answer came from the server’s own zone.

The RA bit is your recursion test. If clients that should be allowed see no ra, check the resolver’s ACLs before anything else. Also check the SERVER: line, since it confirms which resolver answered, which matters when a VPN or a DNS leak test reveals queries going somewhere unexpected.

Compare Recursive and Nonrecursive Queries Without Overreading Cached Answers

Add +norecurse to clear RD:

dig @10.0.0.53 www.example.com A +norecurse

Against a resolver, a nonrecursive query returns only what’s in the DNS cache. An answer means the record is cached; a referral or empty response means it isn’t. The TTL in a cached answer counts down, so two queries a minute apart showing 3,540 and then 3,480 confirm you’re seeing the cache.

Don’t overread this. A cached answer proves the resolver had that data within the TTL; it doesn’t prove the authoritative zone still says the same thing. To check the source, query the authoritative server directly with +norecurse and look for aa. For reverse DNS, use dig -x 203.0.113.10 the same way: PTR records follow their own delegation under in-addr.arpa, often managed by a different provider than your forward zone.

Use PacketTools to Cross-Check DNS Records and Propagation

Your own resolver shows one view. To see what other resolvers hold, the PacketTools DNS propagation checker queries the record from multiple locations, so you can tell whether a mismatch is local caching or an authoritative problem.

For domain-wide checks, the SuperTool runs DNS, MX, SPF, DKIM, DMARC, blacklist, and SSL tests in one pass. No IPs, queries, or test data are logged or stored, and no sign-in is required. Run it after a change, then compare against your dig output: if PacketTools shows the new value and your resolver doesn’t, you’re looking at a cache waiting on its TTL.

How Do You Diagnose Failed or Unexpected Resolution?

Diagnosis starts with the response code, because each one points to a different layer. NXDOMAIN and NODATA come from zone data, SERVFAIL from the resolution chain, REFUSED from policy, and timeouts from the network or a dead service. From there, check Windows recursion settings and forwarders, and treat surprising answers as configuration problems until evidence says otherwise.

Distinguish NXDOMAIN, NODATA, SERVFAIL, REFUSED, and Timeouts

Result Meaning First check
NXDOMAIN Name doesn’t exist Authoritative zone, typos, negative cache
NOERROR, 0 answers Name exists, type missing Correct record type in zone
SERVFAIL Resolution failed Delegation, DNSSEC, upstream reachability
REFUSED Policy rejection Resolver ACLs, wrong server
Timeout No response arrived Port 53, firewall, service state

Confirm the boundary with an authoritative query. An NXDOMAIN with the aa flag proves the name is absent from the zone, so changing resolver settings won’t create it. An authoritative NOERROR beside a recursive SERVFAIL points to DNSSEC validation. Browser errors map onto these codes too: a generic DNS lookup failed message is usually one of the last three rows.

Check Windows Recursion Settings, Forwarders, and Root Hints

On Windows Server, start with PowerShell:

Get-DnsServerRecursion
Get-DnsServerForwarder
Get-DnsServerRootHint

Get-DnsServerRecursion shows whether Enable is True along with timeout and retry values. If someone disabled recursion while hardening an authoritative-only box that also serves clients, external lookups fail. Set-DnsServerRecursion -Enable $true restores it; set it to $false only on servers that should answer for their own zones alone.

For forwarders, test the upstream as if it were the client. If nothing forwards, query a root server: a timeout means you should verify root hints and firewall rules. By default, root hints live in cache.dns under System32Dns. Microsoft notes recursion fails when the query times out, a server in the path doesn’t respond, or a server returns incorrect data. Clear stale entries with Clear-DnsServerCache for the server role and Clear-DnsClientCache for the host’s own lookups.

Investigate Unexpected Answers Before Assuming Cache Poisoning

A wrong IP address triggers fears of DNS cache poisoning, but most unexpected answers have duller causes: a stale cache, split-horizon zones returning internal addresses, a forwarder with its own override, a hosts file entry, or a secondary zone that missed a transfer.

Work through it in order. Query the authoritative DNS server directly with +norecurse. If it returns the wrong value, the zone is the problem. If it’s correct, query each cache layer and compare TTLs. On secondaries, check that the primary’s SOA serial is higher than the secondary’s.

Escalate to a cache poisoning investigation when the wrong answer appears on a resolver whose upstream and authority both return correct data, the TTL doesn’t match anything the authority publishes, and the target IP hosts something resembling a phishing attack page. Capture packets and preserve the cache contents before you flush.

Trace the Query Path Before Changing DNS Settings

Every DNS fix goes faster when you first identify which server gave the answer and whether it came from zone data or a cache. DNS recursion moves the hard work to your resolver, so most surprises live there: a cached NXDOMAIN, an unreachable forwarder, or a TTL that hasn’t expired.

Use this order before you change DNS settings on clients or servers:

  1. Note the response code and the SERVER: line from dig.
  2. Read the flags: ra for recursion offered, aa for authoritative data.
  3. Repeat with +norecurse to see what the cache holds.
  4. Query the authoritative server directly and compare.
  5. Run dig +trace to locate the referral step that breaks.
  6. Check forwarders, root hints, and recursion settings on the DNS resolver.
  7. Flush only the cache layer that holds the stale record.

Keep tests to resolvers you’re authorized to query, and record TTLs before and after each change so you know when every cache layer will refresh. If the trace shows a clean chain and correct authoritative data, the remaining fault sits outside DNS, and your broader network troubleshooting should move to routing, firewalls, or the application itself.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *