Skip to Content

How to Check DNS TTL in Linux

DNS TTL, or time to live, is the element of a DNS record that tells the requester how long the record is valid.

In other words, if the TTL for our DNS record is set to 24 hours, once a browser has resolved that DNS record, it will continue to use that same value for the next 24 hours regardless of whether the DNS record is updated or not.

Understanding DNS TTL Values 

Usually, TTL value is 86400 seconds, which is 24 hours. This is a good starting point for most records. However, we can set higher TTL for MX or CNAME records as they are expected to change very rarely. If our service is critical, it is recommended that we set TTL to 1 hour (3600 seconds).

How to check DNS TTL in Linux

The easiest way to look up TTL settings is to use the dig utility. It is available on Linux, Unix, and Mac OS X.

From the shell (command line), type: dig example.com. This will return the DNS information (including TTL values) for the domain name.

Here’s the output:

; <<>> DiG 9.16.1-Ubuntu <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60955
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;example.com.              IN      A

;; ANSWER SECTION:
example.com.       3600    IN      A       93.184.216.34

;; Query time: 8 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Wed Jun 09 15:30:43 EDT 2023
;; MSG SIZE  rcvd: 56

In this example, the TTL value is 3600 seconds (1 hour).

Let’s see another example.

google.com. 0 IN A 142.251.12.139
google.com. 0 IN A 142.251.12.113
google.com. 0 IN A 142.251.12.100
google.com. 0 IN A 142.251.12.102
google.com. 0 IN A 142.251.12.138
google.com. 0 IN A 142.251.12.101

The output includes the DNS records for the specified domain, including their TTL values. In the above example, the TTL is 0 second.

Note that the TTL values are specified in seconds.

what does DNS ttl 0 mean

A TTL (Time to Live) value of 0 (zero) in DNS (Domain Name System) records has a specific meaning. It indicates that the DNS record should not be cached by resolving DNS servers or clients. When a DNS record has a TTL of 0, it instructs the DNS caching systems to always query the authoritative DNS server for fresh information.

In practical terms, a TTL of 0 means that each time a DNS query is made for the corresponding record, the DNS server must perform a full lookup to obtain the most up-to-date information. This can result in increased DNS query traffic and potentially slower response times, especially if the DNS server or network experiences high volumes of requests.

Setting a TTL of 0 can be useful in scenarios where the DNS record needs to be updated frequently and changes should propagate immediately. It ensures that clients always receive the most current DNS information directly from the authoritative DNS server. However, it’s important to note that relying heavily on TTL 0 can introduce additional load on DNS servers and may impact performance.

When to Use a Long DNS TTL

In general, it is recommended to use shorter TTL values for DNS records. This allows for more flexibility and agility in managing DNS changes, as shorter TTLs result in quicker propagation of DNS updates across the network.

Here are the DNS records that should have longer TTL’s:

  • MX record (points to the mail server)
  • DKIM and SPF (usually configured with MX records)
  • TXT record
  • Records that point to the webserver or CDN, A and CNAME records respectively, will typically have a longer TTL since they are rarely changed. For these, we would want to set a TTL of 12 hours to 1 day.

It’s important to note that when making DNS changes, such as updating IP addresses or switching to new servers, it is recommended to lower the TTL values well in advance. This ensures a smooth transition and faster propagation of the updated DNS information across the network.