DNS Negative Caching
DNS negative caching is the practice of a DNS resolver remembering that a name, or a requested record type at that name, does not exist. The resolver stores authoritative NXDOMAIN and NODATA responses for a limited time, so it can answer repeated questions without contacting the authoritative DNS server each time.
That memory improves performance and reduces load, but it has a common operational consequence: after you create a DNS record, some clients can continue receiving an old “does not exist” answer until the negative cache expires.
The problem it solves
DNS is often queried for names that are absent. A client might try several service names, request an optional record type, or repeatedly look up a hostname before it has been configured. Without negative caching, every unsuccessful lookup would travel through a recursive resolver to the servers authoritative for the DNS zone.
A recursive resolver is the DNS service that performs lookups on a client’s behalf and caches the results. An authoritative server is the server that holds the official records for a zone, such as example.com.
Negative caching lets the resolver say, in effect, “I already asked the authoritative server, and the answer was no.” The result is faster for clients and cheaper for the DNS infrastructure. The answer cannot be remembered forever, though: DNS data can change, so the resolver needs an expiration time.
Two kinds of negative answer
The two negative responses have different meanings:
- NXDOMAIN means the queried DNS name does not exist. For example,
missing.example.comis not a name in the zone at all. - NODATA means the name does exist, but it has no record of the requested type. For example,
api.example.commay have an address record but noTXTrecord.
NODATA is usually represented by a successful DNS response with an empty answer section, rather than by a separate DNS response code. The resolver learns from the response’s authority information that the requested type is absent.
This distinction matters when diagnosing a failure. An NXDOMAIN for a newly created hostname suggests that the name itself was previously absent. A NODATA response suggests that the name existed but the particular record type was not present when the response was cached.
What the authoritative response contains
For a cacheable negative response, the authoritative server normally includes the zone’s SOA record in the authority section. SOA means “Start of Authority”; it is the record that describes the authoritative information and operational parameters for a DNS zone.
The SOA record contains a field called MINIMUM, and the SOA record itself has a DNS TTL. TTL, or time to live, is the number of seconds a cached result may be used before it must be treated as expired.
The negative caching lifetime is derived from the SOA information. In the standards-based behavior used by modern DNS software, the resolver uses the lower of:
- the TTL on the SOA record included in the negative response; and
- the SOA record’s
MINIMUMvalue.
This value is the negative TTL: the maximum time the resolver may remember the NXDOMAIN or NODATA result. It is not necessarily the same as the TTL of ordinary records such as an A or AAAA record.
For example, an authoritative response might effectively say:
status: NXDOMAIN
authority:
example.com. 300 IN SOA ns1.example.com. hostmaster.example.com. ...
SOA MINIMUM: 900
The resolver uses 300 seconds, the smaller value. Depending on the DNS server software and its configuration, administrators may also see a separately configured maximum negative-cache duration. Such a limit can shorten the effective time, but it cannot make an expired negative answer valid again.
What the recursive resolver remembers
Suppose a client asks a recursive resolver for:
new-service.example.com A
The resolver does not have the answer, so it asks the authoritative servers. If the authoritative response says NXDOMAIN and includes a negative TTL of 600 seconds, the resolver stores that negative result with an expiration time ten minutes in the future.
During those ten minutes, another client asking for the same absent name can receive NXDOMAIN immediately from the recursive resolver. The resolver does not need to ask the authoritative servers again. As time passes, the cached result’s remaining TTL decreases. Once it reaches zero, the resolver must perform a new lookup before answering from that entry.
For NODATA, the cached fact is narrower: the name exists, but the requested type is absent. A cached NODATA result for new-service.example.com AAAA does not necessarily mean that a later A lookup will also be answered negatively. The cache tracks the relevant name and record type, subject to the resolver’s DNS rules and implementation.
A resolver can also cache an NXDOMAIN result in a way that covers related questions, because if the name itself does not exist, no record type exists at that name. The exact cache representation is an implementation detail, but the important operational fact is that an NXDOMAIN can affect more than one attempted record lookup.
Why a new record appears to be missing
Consider this sequence:
- At 10:00, a client requests
new-service.example.com. - The authoritative server correctly returns NXDOMAIN because the record has not been created yet.
- The recursive resolver caches that negative response for 15 minutes.
- At 10:02, an administrator creates an
Arecord fornew-service.example.com. - Clients using that recursive resolver continue to receive the cached negative answer until about 10:15.
The authoritative data is now correct, but the resolver is still honoring the earlier answer within its allowed lifetime. This is why adding a record can appear not to work even when the change has already reached the authoritative server.
Different users may see different results because they use different recursive resolvers, and those resolvers may have asked at different times. A direct query to an authoritative server can show the new record while a normal client lookup still returns NXDOMAIN or NODATA.
Diagnosing the delay
When a newly created record seems absent, identify which layer is answering:
- Query an authoritative server to verify that the record exists there.
- Query the recursive resolver used by the affected client.
- Check whether the response is NXDOMAIN or an empty NODATA answer.
- Inspect the SOA-derived TTL and the remaining TTL reported by the resolver.
Flushing a local operating-system or application DNS cache may remove one layer of memory, but it cannot remove an entry held by an upstream recursive resolver. Usually the practical fix is to wait for the negative TTL to expire. For planned changes, administrators can lower the relevant negative-cache setting in advance, while remembering that resolvers which already cached an older negative response will retain it until that older TTL runs out.