TTL and DNS caching explained
TTL is the number of seconds a DNS answer may be cached, and every layer between you and the authoritative server (resolver, OS, browser) keeps its own copy until that time runs out.
- Updated Nov 27, 2026
- Markdown
Plan a DNS change around TTL, read remaining TTL with dig and flush local caches on Linux and macOS.
- dig installed
- A domain you can edit DNS for
TTL (time to live) is how many seconds a DNS answer may be reused before it must be fetched again. Every record in a zone has one. The copy of the answer is kept by several layers, each with its own clock, which is why a change you made a minute ago can look live from one device and missing from another. This lesson goes deeper than DNS propagation and TTL, which covers the basics.
How it works#
A lookup passes through a chain of caches before it reaches the authoritative server:
- The application. Browsers keep a small DNS cache of their own.
- The operating system’s resolver, such as systemd-resolved on many Linux distributions or mDNSResponder on macOS.
- A recursive resolver run by your ISP, company or a public service. This is the biggest cache and serves many users.
- The authoritative nameserver that actually holds the zone.
When a recursive resolver fetches a record, it stores it with the TTL it received. Each time a client asks, it answers from the cache and counts the TTL down. When it reaches zero, the entry is dropped and the next question goes upstream. Lower layers may add their own limits or ignore very small or very large values, so the TTL is a request, not a guarantee.
Read the remaining TTL#
Query a public resolver twice a few seconds apart:
dig @1.1.1.1 example.com A +noall +answer
sleep 10
dig @1.1.1.1 example.com A +noall +answerThe second answer shows a smaller number in the TTL column. That is the time left in that resolver’s cache. Querying the authoritative server shows the full configured TTL every time, since it is not counting down:
dig @ns1.example.net example.com A +noall +answerBe aware that large public resolvers are made of many servers, so repeated queries may hit different caches and show different remaining times.
Lower the TTL before a change#
The plan for moving a site to a new IP has a fixed order, and the timing matters:
- Note the current TTL, for example 86400 (one day).
- At least that long before the move, lower the TTL on the record, for example to 300.
- Wait until the old TTL has passed. Caches that stored the answer under the old, long TTL need that time to expire.
- Change the record to the new IP.
- Verify, and after things settle, raise the TTL again to reduce query load.
Lowering the TTL at the same moment as the change does nothing for caches that already hold the old value under the long TTL. This is the single most common mistake. See Point a domain at your server for the record you are changing.
Negative caching and the SOA#
Resolvers also cache failures. If someone looked up new.example.com before you created it, the resolver stored an NXDOMAIN answer (the name does not exist). That negative answer is cached for a time taken from the zone’s SOA record (RFC 2308 uses the lower of the SOA TTL and its minimum field). Read it with:
dig example.com SOA +noall +answerThe last number in the data is the minimum. A long value means a record you create may stay invisible to some users for that long. If you plan a launch, create the record before anyone is told about the name, and keep the SOA minimum modest. See What is a DNS zone for the SOA fields.
Flush local caches#
Flushing only clears your own machine. It cannot touch your ISP’s resolver or anyone else’s.
On Linux with systemd-resolved:
resolvectl statistics # shows cache size and hits
sudo resolvectl flush-cachesOn macOS (commands have changed between releases, these work on recent ones):
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponderBrowsers keep their own cache. In Chrome and Edge you can open chrome://net-internals/#dns and clear the host cache. Restarting the browser also works. Test with dig instead of a browser when you want a clean answer, since dig skips the application cache.
Check it worked#
Compare three views and make sure they agree once caches have expired:
dig @ns1.example.net example.com A +short # authoritative, the truth
dig @1.1.1.1 example.com A +short # a public resolver
dig example.com A +short # your configured resolverIf the first is correct and the others are old, caches are the reason, and waiting for the TTL is the fix. If the first is wrong, the edit never reached the authoritative zone.
Edge cases and gotchas#
- Long TTL on NS records: nameserver records at the parent zone often have long TTLs that you cannot change. See DNS propagation myths.
- Resolvers that ignore TTL: a few resolvers enforce a minimum or maximum, so a 60 second TTL may be kept longer than expected.
- Every layer counts: flushing your OS cache does nothing if the resolver upstream still holds the old record.
- Short TTL costs load: a very low TTL means more queries to your nameservers and slightly slower first lookups.
- Different records, different TTLs: www and the apex can have different TTLs, so one can update before the other.
- Negative cache surprise: testing a name before creating it can make the failure stick for a while on that resolver.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Old IP still returned after the change | The resolver cache holds the old answer | Query the authoritative server, then wait for the remaining TTL |
| New record shows NXDOMAIN | Negative caching from an earlier lookup | Wait for the SOA minimum, or test through a different resolver |
| Browser shows old site, dig shows new IP | Browser or OS cache | Flush the OS cache and restart the browser |
| Lowering TTL did not speed up the move | It was lowered too late | Next time lower it a full old-TTL period ahead |
| resolvectl: command not found | The system does not use systemd-resolved | Find the local cache service (nscd, dnsmasq) and restart it |
| Different networks see different IPs | Separate resolver caches expire at different times | Expected; verify with the authoritative answer |
Quick reference#
dig @1.1.1.1 example.com A +noall +answer # remaining TTL at a resolver
dig @ns1.example.net example.com A # full TTL at the source
dig example.com SOA +noall +answer # negative caching time
sudo resolvectl flush-caches # Linux systemd-resolved
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder # macOSRelated lessons#
- DNS propagation and TTL: the short introduction to this topic.
- DNS propagation myths: why “propagation” is really cache expiry.
- Check DNS with dig: the commands used above in detail.
- What is a DNS zone: where the SOA and TTLs live.
- Fix a domain that does not resolve: a step by step checklist.
Next#
Continue with DNS propagation myths.
Check what you learned
Frequently asked questions
What is a good TTL for a DNS record?
Common values are 300 to 3600 seconds for records you may change, and longer for stable ones. Pick a value that matches how quickly you need to move traffic, and lower it ahead of planned changes.
How do I flush the DNS cache on Linux?
On systems with systemd-resolved, run resolvectl flush-caches. Other setups use their own cache, such as nscd or dnsmasq, which have their own flush or restart commands.
How do I flush the DNS cache on macOS?
Run sudo dscacheutil -flushcache followed by sudo killall -HUP mDNSResponder. The exact commands have varied between macOS releases, so check Apple's documentation if they have no effect.
Why does my new DNS record not show up yet?
Some cache still holds an earlier answer, possibly a negative one saying the name did not exist. Query the authoritative server directly to confirm the record exists, then wait for caches to expire.
Sources
Keep going: guides and tutorials
- Self-Hosted Static Site Hosting: Deploy a Folder With Levelrail Self-hosted static site hosting from a plain folder: one deploy command, _redirects, _headers and a custom 404 honored, plus a one command rollback.
- Deploy Next.js on a VPS With Docker, Git Push and HTTPS Deploy a Next.js app to your own VPS with Docker, a health check, HTTPS and rollback. Includes the NEXT_PUBLIC build trap that leaves variables empty.