Sub topic 7
Recursive resolvers
A recursive resolver is the server that does the work of finding an answer on behalf of other machines. This chapter assumes you know what a stub resolver does (covered in the previous chapter), what a resource record is, and how to run dig. The step-by-step trace from the root servers down is the next chapter. Here the focus is on the resolver itself: what it promises, what it keeps, who runs it, and how it fails.
Recursion and iteration
Two terms describe two different jobs:
- Recursive query. The client asks for a final answer and expects the server to do whatever it takes to get one. A stub resolver sends recursive queries.
- Iterative query. The client accepts a referral ("I don't know, ask these servers") and follows it. A recursive resolver sends iterative queries to authoritative servers.
So one resolver plays both roles. To its clients it behaves recursively. To the authoritative servers it behaves iteratively. An authoritative server never recurses for you. It answers only for the zones it hosts, or it refers you onward.
The header flags in a response show this. rd (recursion desired) is set by the client. ra (recursion available) is set by a server willing to recurse for that client.
dig @8.8.8.8 example.com A | grep flags
dig +norecurse @a.iana-servers.net example.com A | grep flagsThe first query typically shows flags: qr rd ra. The second goes to an authoritative server for example.com and typically shows qr aa, with no ra. The aa flag marks an authoritative answer. If you ask an authoritative server for a name outside its zones, it usually returns REFUSED, because it does not recurse.
What a resolver does for each query
A recursive resolver handles each client query in roughly this order:
- Check its cache for the exact name, type and class. If a record is present and its TTL has not expired, answer immediately.
- Check whether it already knows the nearest delegation, for example the NS records for
example.com. If so, skip the higher levels. - Otherwise start at the root, using a built-in list of root server addresses (the root hints).
- Follow referrals until it gets an answer, an error, or gives up.
- Cache what it learned, including failures, and reply to the client.
Step 2 is why most lookups never touch the root servers. The resolver caches delegations, so a lookup for www.example.com usually starts at the example.com name servers.
Who runs resolvers
| Type | Typical address | Strengths | Drawbacks |
|---|---|---|---|
| ISP resolver | Handed out by DHCP | Close to you, often fast | Policies vary, may log or redirect failed lookups |
| Public resolver | `8.8.8.8`, `1.1.1.1`, `9.9.9.9` | Large shared cache, consistent behavior | You send your query history to a third party |
| Local forwarder (home router, `dnsmasq`) | `192.168.1.1` | Caches for the LAN, can serve local names | Usually forwards upstream rather than resolving itself |
| Self-hosted (Unbound, BIND, Knot Resolver) | Your own server | Full control, no third party | You maintain it and must keep it patched |
A forwarder does not walk the hierarchy. It relays queries to another recursive resolver and caches the replies. A full recursive resolver walks the hierarchy itself. Many home routers are forwarders, so the "resolver" your laptop talks to may be two or three hops from the machine that actually contacts authoritative servers.
Resolvers should answer only their own clients. A resolver that accepts recursive queries from the whole internet is an open resolver. Attackers use open resolvers in reflection attacks, where a small spoofed query produces a large reply sent to the victim. Restrict recursion by source address, as in this Unbound fragment:
# /etc/unbound/unbound.conf.d/local.conf
cat <<'EOF'
server:
interface: 0.0.0.0
access-control: 127.0.0.0/8 allow
access-control: 192.168.0.0/16 allow
access-control: 0.0.0.0/0 refuse
EOFThe block above only prints the configuration. To use it, write the lines between EOF markers into the file named in the comment and reload Unbound.
Seeing which resolver you use
On a systemd-based Linux machine, /etc/resolv.conf often points at a local stub listener, not at the real upstream. Ask the system what it actually uses:
cat /etc/resolv.conf
resolvectl statusresolvectl status lists the DNS servers per network interface. On macOS, scutil --dns gives the same information. A common surprise is that a VPN or Wi-Fi network installs its own resolver for some domains. In that case two names on the same machine resolve through different servers.
Resolver behavior you can observe
Shared cache across clients. A resolver serves many clients from one cache. If one user looks up a name, the next user gets the cached answer. You can observe it by repeating a query and watching the TTL count down:
dig @1.1.1.1 +noall +answer example.com A
sleep 5
dig @1.1.1.1 +noall +answer example.com AThe second TTL is usually lower by about five seconds. Large public resolvers run many cache nodes behind one address, so successive queries may hit different caches and show unrelated TTL values.
Cache-only probing. dig +norecurse @resolver name asks the resolver to answer only from its cache. An empty NOERROR reply means the name is not cached. Some resolvers refuse such queries.
Negative caching. Resolvers also cache failures: NXDOMAIN (the name does not exist) and "no data" (the name exists but not for that type). The lifetime comes from the zone's SOA record, specifically its negative-caching TTL. This is why a name that you created a minute after a failed lookup may still appear missing.
Query name minimization. A privacy-minded resolver, following RFC 9156, sends only as much of the name as each server needs. The root servers see com., not www.example.com.. Unbound and Knot Resolver enable this by default.
Retries and server selection. A resolver tracks response times for each authoritative server and prefers fast ones. If a query times out it retries another server in the NS set. If a UDP reply is truncated (the tc flag), it retries over TCP.
Common errors and what they mean
| Symptom | Likely cause |
|---|---|
| `SERVFAIL` | The resolver could not get a usable answer: all authoritative servers timed out, a delegation points at servers that do not answer (a *lame delegation*), or DNSSEC validation failed |
| `NXDOMAIN` | The name does not exist. It may be a typo, or a stale negative-cache entry |
| `REFUSED` | The server will not recurse for your address, or you queried an authoritative server for a zone it does not host |
| Timeout, no reply | Unreachable resolver, a firewall blocking UDP or TCP port 53, or an overloaded server |
| Different answers from two resolvers | Different cache contents, geo-aware (location-dependent) answers from the authoritative side, or a resolver that filters or rewrites results |
To separate a resolver problem from a zone problem, query the same name against two or three resolvers and then against the authoritative servers directly:
dig @8.8.8.8 example.com A +noall +comments
dig @1.1.1.1 example.com A +noall +comments
dig +norecurse @a.iana-servers.net example.com A +noall +commentsThe +comments output includes the status: field. If the authoritative server answers correctly but a resolver returns SERVFAIL, the fault is in the resolution path, not the zone data.
Exercise
A colleague says that example.com resolves for them but returns SERVFAIL for you. Both of you use different resolvers. Describe three dig commands you would run and how you would interpret the results to decide whether the problem is in your resolver or in the zone.
Show answer
Run dig @<your resolver> example.com A +noall +comments to confirm the SERVFAIL status. Run dig @<your colleague's resolver> example.com A +noall +comments to confirm that it returns NOERROR with an answer. Run dig +norecurse @<an authoritative server for example.com> example.com A (find one with dig +short NS example.com). If the authoritative server answers with the aa flag and correct data, the zone is fine and the fault is in your resolver's path. Possible causes are a stale or broken cached delegation, blocked traffic to an authoritative server, or a DNSSEC validation failure on your resolver. If the authoritative server times out or returns errors, the problem is in the zone or its name servers, and your colleague's resolver is likely answering from cache.