How to understand TTL values in dig command output

dns

I am reading about how DNS works in general. From the wiki entry of TTL, I understand TTL (Time to Live) occur in the Domain Name System (DNS), where they are set by an authoritative name server for a particular resource record. When a caching (recursive) nameserver queries the authoritative nameserver for a resource record, it will cache that record for the time (in seconds) specified by the TTL.

Now, I needed to use the Linux CLI tools (dig) to figure out what is the actual TTL set in the authoritative name server and so used my command as below.

dig +trace +nocmd +noall +answer +ttlid a www.stackoverflow.com

#I have omitted the root name server output for better readability. 

www.stackoverflow.com.  300 IN  CNAME   stackoverflow.com.
stackoverflow.com.  300 IN  A   198.252.206.140
;; Received 80 bytes from 173.245.59.4#53(cf-dns02.stackoverflow.com) in 9 ms

As I could see from the A record of stackoverflow.com., the TTL value in the authoritative name server is 300.

So, does this mean, if I search for stackoverflow.com after 300 seconds or 5 minutes, the IP address of stackoverflow.com would be resolved all the way from the .com domain?

Best Answer

No; not all the way from the .com domain (actually I think you meant from the root domain?).

The NS records for stackoverflow.com have a TTL of 172800, so those are cached a lot longer than the 300 seconds of the www.stackoverflow.com CNAME record and the stackoverflow.com A record. So after those CNAME and A records have expired, the NS records will probably still be cached and hence those nameservers can be questioned about www.stackoverflow.com (and then stackoverflow.com).

BTW I wouldn't have given both www.stackoverflow.com and stackoverflow.com a TTL of just 300, that means twice as many DNS requests without any immediately evident advantage IMHO.

Related Question