TTL is an acronym for “Time To Live.” You can set TTL for the DNS record that defines how long a resolver supposed to cache the DNS query before the query expires. TTL typically used to reduce the load on your authoritative name servers and to speed up DNS queries for clients. This page explains how to find Time-To-Live (TTL) for a DNS record using Linux or Unix command-line options.
Find Out Time-To-Live (TTL) for a DNS record
- Open the terminal application on your Linux/macOS/Unix desktop
- Type dig TYPE DomainNameHere NS1-AUTHNAME-SERVER-HERE and note down TTL from the answer section
- To find TTL value directly from the authoritative DNS server, pass the +noauthority +noquestion +noadditional +nostats option to dig command
- Pass the +ttlunits option to the dig to display TTL value in a human-readable time format or units such. For instance, 5m TTL means 5 minutes
Let us see all examples in details.
How to see Time-To-Live (TTL) DNS record
The syntax is as follows for the dig command:
dig TYPE domain
dig TYPE domain auth-name-server-here
dig [options] TYPE domain auth-name-server-here
To check the TTL for www.cyberciti.biz using local DNS resolver (result might be cached), run:
dig A www.cyberciti.biz
So TTL for www.cyberciti.biz DNS A record is 176 seconds.
How can I get the TTL for www.cyberciti.biz using authoritative DNS server
First, find the NS for given domain:
dig +short NS cyberciti.biz
Sample outputs:
fay.ns.cloudflare.com. clay.ns.cloudflare.com.
Now, we can either use ‘fay.ns.cloudflare.com.’ or ‘clay.ns.cloudflare.com.’ as follows to avoid caching issues:
dig A www.cyberciti.biz @fay.ns.cloudflare.com
Common DNS record types for TTL with examples
- A or AAAA Record : IPv4 or IPv6 address. (dig AAAA www.cyberciti.biz)
- CNAME Record : Canonical Name or alias. (dig CNAME server1.cyberciti.biz)
- MX Record : Mail server/mail exchanger. (dig MX nixcraft.com)
- TXT Record : Used for various purpose such as describing SPF record. (dig TXT cyberciti.biz)
- NS Record : Authoritative DNS. (dig NS cyberciti.biz)
How do I find my DNS TTL?
So far, all examples give out a long answer from the dig. However, if you need just the TTL value, you can try the following syntax:
dig +nocmd +noall +answer +ttlid A www.cyberciti.biz
dig +nocmd +noall +answer +ttlid AAAA www.cyberciti.biz
dig +nocmd +noall +answer +ttlid MX cyberciti.biz
Sample outputs from the last command:
cyberciti.biz. 299 IN MX 1 aspmx.l.google.com. cyberciti.biz. 299 IN MX 10 aspmx2.googlemail.com. cyberciti.biz. 299 IN MX 10 aspmx3.googlemail.com. cyberciti.biz. 299 IN MX 5 alt1.aspmx.l.google.com. cyberciti.biz. 299 IN MX 5 alt2.aspmx.l.google.com.
How to get friendly human-readable time units for my TTL
Pass the +ttlunits as follows to display the TTL in friendly human-readable time units of “s”, “m”, “h”, “d”, and “w”, representing seconds, minutes, hours, days and weeks:
dig +nocmd +noall +answer +ttlunits A www.nixcraft.com
dig +nocmd +noall +answer +ttlunits MX nixcraft.com
dig +nocmd +noall +answer +ttlunits NS cyberciti.biz
See Time-To-Live (TTL) is now defined in a nice format such as 1d (one day) or 5h42m51s (five hourse 42 mintues and 51 seconds) for given DNS record.
A note about Windows users to find Time-To-Live (TTL) DNS record
You need to use the nslookup command. First, open a command prompt window by visiting Start > Command Prompt (also called as cmd.exe) and type the following command:
nslookup -debug www.cyberciti.biz
Sample outputs:
Server: 192.168.2.254 Address: 192.168.2.254#53 ------------ QUESTIONS: www.cyberciti.biz, type = A, class = IN ANSWERS: -> www.cyberciti.biz internet address = 104.20.186.5 ttl = 300 -> www.cyberciti.biz internet address = 104.20.187.5 ttl = 300 AUTHORITY RECORDS: ADDITIONAL RECORDS: ------------ Non-authoritative answer: Name: www.cyberciti.biz Address: 104.20.186.5 Name: www.cyberciti.biz Address: 104.20.187.5 ------------ QUESTIONS: www.cyberciti.biz, type = AAAA, class = IN ANSWERS: -> www.cyberciti.biz has AAAA address 2606:4700:10::6814:bb05 ttl = 299 -> www.cyberciti.biz has AAAA address 2606:4700:10::6814:ba05 ttl = 299 AUTHORITY RECORDS: ADDITIONAL RECORDS: ------------ Name: www.cyberciti.biz Address: 2606:4700:10::6814:bb05 Name: www.cyberciti.biz Address: 2606:4700:10::6814:ba05
In this final example, look up for TTL for ‘AAAA’ record for ‘www.cyberciti.biz’ using authoritative name server named ‘clay.ns.cloudflare.com’
nslookup -debug -type=aaaa www.cyberciti.biz clay.ns.cloudflare.com
Conclusion
Time to live (TTL) is a value that implies how long should the data be kept before discarding by DNS resolvers. You learned how to use the dig command to find TTL for troubleshooting purposes. See wikipedia page here for more info on Time-To-Live (TTL) for DNS.
🐧 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |