A recursive query is a DNS request where the queried name server performs full name resolution on the client's behalf and returns either a final answer or an error, as opposed to a referral. The client signals this intent by setting the recursion desired (RD) flag in the DNS message header, and the resolver contacts other authoritative servers as needed, caching results and returning only the final outcome. Recursive resolvers are critical to application performance and availability, but require careful security hardening through access control lists to prevent abuse as open resolvers in denial-of-service attacks and protection against cache poisoning.
How recursive query works
In a recursive query, the client sets the recursion desired (RD) flag in the DNS message header. The receiving server, if it offers recursion, takes on the work of resolving the name and returns only the final result.
- Client sends the query: A stub resolver on the client sends a query with the RD flag set to its configured recursive resolver.
- Resolver checks its cache: The recursive resolver looks for a valid cached answer. If one exists, it returns it immediately.
- Resolver queries other servers: On a cache miss, the resolver sends iterative queries, usually starting at a root server. It follows referrals to top-level domain servers and then to the authoritative server for the zone.
- Resolver caches the result: The resolver stores the answer for the time given by the record's time to live (TTL).
- Resolver replies to the client: The resolver returns the final answer, or an error such as NXDOMAIN or SERVFAIL, with the recursion available (RA) flag set.
The client sees one request and one response, however many servers the resolver contacts. A server may refuse recursion, in which case it answers only from its own data or returns a referral or refusal. Authoritative-only servers typically do not offer recursion.
Common recursive query issues
A resolver that answers recursive queries from any source address can be used in reflection and amplification attacks. Restrict recursion with access control lists to internal client ranges and check that it is not reachable from the internet.
Clients receive REFUSED responses when their subnet is missing from the resolver's allowed list. This often appears after a new subnet is deployed and the access list is not updated.
After a restart or cache flush, every query becomes a cache miss and triggers a full walk from the root. Users see slow page loads until the cache warms again.
When an authoritative server for a zone is unreachable or returns lame delegations, the resolver cannot finish resolution and returns SERVFAIL. The client only sees a failure, so the fault is found by tracing the iterative queries on the resolver.
A resolver keeps answers until the TTL expires, so a changed record may not appear for some clients. Engineers see inconsistent results between resolvers after a change until caches expire or are flushed.