OakType / Runtime Notes

Negative caching is the resolver setting nobody tunes

Domain DNSTools dig, unbound, systemd-resolvedRevised 2026-09-14

Most resolver tuning advice is about cache size. The setting that actually changes behaviour under failure is how long a negative answer is kept, and whether the resolver conflates "name does not exist" with "name exists but has no record of this type".

Two negative answers, one cache

ResponseRFC 2308 meaningWhat it caches
NXDOMAINThe name does not existAbsence of the whole name
NODATAThe name exists, no records of this typeAbsence of one RRset only

The distinction matters during a cutover. If a zone publishes only A records and a client asks for AAAA, the correct answer is NODATA with the zone's SOA minimum as the negative TTL. A resolver that treats that as NXDOMAIN will keep failing the name even after the AAAA record appears.

# watch the negative TTL the authority actually returns
dig +norecurse AAAA example.org @ns1.example.org | grep -A1 'AUTHORITY SECTION'

# check what the local resolver cached
dig AAAA example.org @127.0.0.1 +ttlunits

Sizing the cache

For a resolver serving a few hundred clients, msg-cache-size and rrset-cache-size dominate memory use, not the number of entries. Unbound's defaults — 4 MiB and 4 MiB — are conservative but rarely the bottleneck; a 2 % miss rate on a warm cache costs more in latency than the memory ever would.

server:
  msg-cache-size: 64m
  rrset-cache-size: 128m
  cache-min-ttl: 60
  cache-max-ttl: 86400
  serve-expired: yes
  serve-expired-ttl: 3600
  prefetch: yes

serve-expired is the interesting one: it answers from a stale entry while refreshing it in the background, trading a little staleness for a large reduction in tail latency when an authoritative server is slow. Combined with a short cache-min-ttl it makes upstream outages much less visible.

Caution. serve-expired + a long serve-expired-ttl will happily serve a decommissioned address for an hour. For records you actually rotate, keep the stale window shorter than the rotation interval.

Verifying a change

Measure rather than assume: query the resolver in a loop while flushing, and compare the p95 against the same loop pointed at a public resolver. A change that does not move the p95 is a change that did not matter.

for i in $(seq 200); do
  dig +short +tries=1 +time=1 example.org @127.0.0.1 > /dev/null
  echo $?
done | sort | uniq -c