brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: run dig twice and watch the TTL count down

Dig
~/tips/tip-dns-dig-ttl-countdown

dig +noall +answer example.com

Shows only the answer section of a DNS lookup, so you can read the TTL.

The TTL is the number in a DNS answer that most people ignore. It is also the easiest way to tell whether you are looking at a fresh answer or a cached one.

Show only the answer section, so the TTL is easy to spot, and query your normal resolver twice:

dig +noall +answer example.com
sleep 10
dig +noall +answer example.com

+noall switches every output section off and +answer turns the answer section back on. The second column is the TTL in seconds. If the second run shows a lower number, your resolver answered from its cache and is counting down. If it shows the full value again, the cache was empty or the record is not being cached.

This is also how you see how long a DNS change takes to spread. Lower the TTL before you move a site, wait for the old TTL to run out, then switch. The caveat: some resolvers set their own minimum or maximum TTL, so what you see is not always what the zone says. Ask the authoritative server directly with @ns to see the original.

If you need the clean numbers, query the authoritative server for the zone instead of the resolver, for instance with dig +noall +answer example.com @ns1.example.com. There the TTL will not count down, because nothing is cached.

Further reading: dig manual (BIND 9), On this site: dig +ttlunits makes TTLs readable, On this site: dig can speak DoH and DoT itself

Going deeper: Guide: dig for beginners, look up DNS records and read the answer

More Dig tips dig +noall +answer DS example.com dig nope.iana.org @9.9.9.9 | grep -E 'status|SOA' dig +search nas dig @8.8.8.8 www.google.com +subnet=203.0.113.0/24 dig +yaml example.com A All Dig tips (36) All topics

Link