Caching, TTLs and Failures
There is no such thing as propagation, and four ways to fail.
Nothing propagates. Resolvers count down a number you chose.
Where answers are cached
Four layers, each with its own copy:
| Layer | Clears when |
|---|---|
| The application | it restarts, usually |
| The operating system | you flush it, or it expires |
| The recursive resolver | the TTL runs out |
| Another user’s resolver | never, as far as you are concerned |
You control none of these. The only lever is the TTL you publish, and it applies only to caches that have not already stored the old answer.
Watching a TTL count down
Two queries, three seconds apart:
dig @1.1.1.1 +noall +answer example.com | awk '{print $2}' | head -1208 then 205. Nothing was pushed — the resolver counts down from the published TTL and
asks again at zero.
A TTL that is not a round number proves the answer came from cache. The authoritative server always answers at the full value:
dig @elliott.ns.cloudflare.com +noall +answer example.com \
| awk '{print $2}' | head -1Choosing a TTL
| TTL | Suits |
|---|---|
| 60–300 | a record you may need to change quickly |
| 3600 | the usual default |
| 86400 | NS and MX, which rarely change |
A short TTL means more queries and faster changes; a long one, fewer queries and slower
recovery. NS records usually sit at the top of that range:
dig @elliott.ns.cloudflare.com +noall +answer NS example.com \
| awk '{print $2}' | head -1Negative caching
Failures are cached too, using the SOA minimum from chapter 3 — returned in the
authority section of the failure:
dig @1.1.1.1 +noall +authority nosuch-xyz987.com \
| awk '{print $1,$4}' | head -1dig @1.1.1.1 +short SOA com | awk '{print $NF}'A typo’d record keeps failing for 900 seconds after you fix it — chapter 3’s fifth SOA
number finally mattering.
Propagation explained
Nothing is distributed and nothing is pushed. When you change a record:
- Your authoritative servers answer with the new value immediately.
- Every resolver holding the old answer keeps serving it until its TTL expires.
- Each resolver then asks again, independently, and gets the new value.
Two resolvers hold the same record with different time remaining, because each cached it when it happened to ask:
for r in 1.1.1.1 8.8.8.8; do
printf '%-10s ' $r
dig @$r +noall +answer example.com | awk '{print $2}' | head -1
donePlanning a migration
The order matters, and most people reverse it:
| Step | When |
|---|---|
| Lower the TTL to 300 | at least one old-TTL period before |
| Wait for the old TTL to expire | the long wait, done early |
| Change the record | now takes 5 minutes to settle |
| Raise the TTL again | once it is working |
The record’s own TTL tells you how long step two takes:
dig @elliott.ns.cloudflare.com +noall +answer example.com \
| awk '{print $2}' | head -1NOERROR with no answer
The name exists. The record type does not:
dig @1.1.1.1 +noall +comments MX one.one.one.one | grep '^;; flags'NOERROR with ANSWER: 0 — the question was fine, and there is no such record here.
NXDOMAIN and SERVFAIL
NXDOMAIN means the name itself does not exist anywhere:
dig @1.1.1.1 nosuch-xyz987.com | grep -oE 'status: [A-Z]+'SERVFAIL means something broke on the way, usually DNSSEC — chapter 4:
dig @1.1.1.1 dnssec-failed.org | grep -oE 'status: [A-Z]+'REFUSED and timeouts
REFUSED is a server declining — here, asked about a zone it does not hold:
dig @elliott.ns.cloudflare.com google.com 2>/dev/null \
| grep -oE 'status: [A-Z]+'A timeout is not a status at all, because no reply arrived:
dig @192.0.2.1 +time=2 +tries=1 example.comFour failures, four causes. REFUSED is configuration at the server; a timeout is a
network problem, a firewall, or a machine that is not there.
Diagnosing in order
Work outwards from yourself:
| # | Check | Command |
|---|---|---|
| 1 | Does another resolver agree? | dig @1.1.1.1 and dig @8.8.8.8 |
| 2 | Is the delegation right? | dig +trace |
| 3 | Does the authoritative server have it? | dig @<its NS> |
| 4 | Is it a DNSSEC failure? | dig +cd |
| 5 | Is it cached somewhere? | compare the TTL to the full value |
Step 1 takes one line:
for r in 1.1.1.1 8.8.8.8; do
printf '%-10s ' $r
dig @$r +short example.com | sort | xargs
done