The Domain Name System (DNS) is often referred to as the internet’s phonebook, translating human-readable domain names like www.example.com into IP addresses that computers use to identify each other on the network.
The most overlooked component of DNS, even among the technically adept, is the Time to Live (TTL) value. Understanding what TTL means and how it affects both your query counts and update times is essential for anyone managing a website or network.
A zone’s TTL influences DNS performance, caching behavior, and how quickly changes propagate across the internet.
What Does TTL Mean in DNS?
Time to Live (TTL) in DNS refers to the duration (in seconds) that a DNS record is cached by a DNS resolver or server before it needs to fetch a fresh copy from the authoritative nameserver. Essentially, TTL determines how long a resolver (the nameservers that ask questions about domains and hostnames) should store the information about a domain’s DNS records before querying the authoritative DNS (the nameservers that answer queries about zones they host) again.
Purpose of TTL in DNS Records
Without caching, resolvers would have to redo a query every time it needs to know the value of a given domain or hostname – imagine a webpage where there are a dozen embedded imaged, all anchored to the same image hosting server.
When rendering that page, the browser needs to lookup that image host, if there was no such thing as caching, it would have to look it up every time. It would slow the page rendering speed to a c-r-a-w-l.
So resolvers cache the answer to their DNS lookups, but they also need to know how long they can hang onto that old value for, in case it ever changes.
This is why we have TTLs:
- Caching Efficiency: Query caching reduces the number of queries sent to authoritative DNS servers by allowing intermediate DNS servers to remember the responses for a set period, the TTL controls the length of that period.
- Performance Enhancement: By caching DNS records, TTL reduces latency for end-users, leading to faster website load times.
- Load Reduction: Decreases the workload on authoritative DNS servers by limiting the frequency of otherwise repetitive queries.
How TTL Affects DNS Performance
Impact on DNS Query Speed
When a DNS resolver has cached a DNS record, it can respond to queries more quickly than if it had to fetch the information from the authoritative server every time. This improves overall DNS performance and user experience.
Effect on DNS Propagation Time
DNS propagation refers to the time it takes for changes to a DNS record to be updated across all DNS servers worldwide. TTL directly affects this propagation time:
- Lower TTL Values: Lead to faster propagation but increase the number of queries to the authoritative DNS server.
- Higher TTL Values: Slow down propagation but reduce the load on DNS infrastructure.
Common TTL Values and Their Uses
Understanding TTL Units
If you look at a domain’s SOA record (Start-of-Authority) record (which you can edit in your control panel here), it breaks out into five separate fields:
- Serial
- Refresh
- Retry
- Expire
MinimumNegative Cache
The first three are for signalling between nameservers and we handle most of that under-the-hood so you shouldn’t need to worry about it.
The only ones you really care about is the Expire Interval and then last one.
SOA Expire Field
If something goes wrong with your primary nameservers (or even all of your authoritative nameservers), any resolvers who have your zone cached will keep it for the amount of time specified in the Expire field – so we like to go long here, 7 days, or even 10 days. We’ve seen some crazy values here.
As long as the age of the cache is lower than the value in this field, the resolvers will keep using these values even if they know they’re supposed to refresh, but can’t because there’s a problem with the authoritative nameservers.
Once this value elapses – the resolver drops the zone, because it decides the cached info is so old, it may be out of date. Hopefully any issues on the primary nameservers get resolved before this timeframe.
The Negative Cache Field
This used to be the main Time-To-Live setting – and probably 90% of techies still think this is your TTL. It isn’t, this is used to be the case, but it was changed to govern how long a nameserver should cache a negative response on a query.
The main TTL is now taken from the individual TTL value of the SOA RR itself.
If you’re eyes just glazed over, don’t worry about it. Just enter the value you want in the control panel and we take care of it:
Configuring TTL in DNS Records
Where to Find and Set TTL Values
TTL values are configured in your DNS management interface, provided by your domain registrar or DNS hosting service. Each DNS record type (A, AAAA, CNAME, MX, etc.) can have its own TTL setting.
Scenarios Impacting TTL Choices
Website Migrations
Before migrating a website to a new server, lowering the TTL (e.g., to 300 seconds) ensures that DNS changes propagate quickly, minimizing downtime.
DNS Record Updates
When updating DNS records, such as changing IP addresses, a lower TTL allows the new information to reach users faster.
High-Traffic Websites
For websites with high traffic, increasing your TTL values can reduce the load on DNS servers, enhancing stability. If you want to learn more about this, see our article on minimizing your DNS query overages through adjusting these values.
Tools for Checking and Troubleshooting TTL
Using dig for DNS Queries
The dig command-line tool can display TTL values for DNS records:
$ dig example.com
; <<>> DiG 9.11.5-P4-5.1+deb10u11-Debian <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46231
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: ad0b757ab4637cd901000000671bc3e2349ba9b040f6af7b (good)
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 3595 IN A 93.184.215.14
;; Query time: 1 msec
;; SERVER: 64.68.199.53#53(64.68.199.53)
;; WHEN: Fri Oct 25 16:14:26 UTC 2024
;; MSG SIZE rcvd: 84
Look at the ANSWER SECTION where the response is listed, the TTL is the second field – and the value it’s showing is how much time is left on the TTL. Repeatedly running this dig command and seeing this value coming down confirms you are getting response from a resolver that is answering from it’s cache.
You could ask the authoritative nameserver directly:
$ dig easydns.net @dns1.easydns.com
;; ANSWER SECTION:
easydns.net. 600 IN A 64.68.200.48
Online DNS Lookup Tools
Web-based tools like DNS checker websites can also display TTL values without needing command-line access.
Common TTL-Related Issues
• Stale Records: High TTL values may cause outdated records to linger.
• Increased Load: Very low TTLs can increase the load on authoritative DNS servers due to more frequent queries.
Advanced Topics
TTL and Dynamic DNS (DynDNS TTL)
Dynamic DNS services update DNS records automatically when an IP address changes. TTL settings in DynDNS affect how quickly these changes propagate.
TTL in Reverse DNS Lookups
Reverse DNS translates IP addresses back to domain names. TTL settings here are important for services like email servers, where reverse DNS is used for spam prevention.
Fastest DNS Servers and TTL
Using the fastest DNS servers can improve DNS query times. However, TTL settings still dictate how long records are cached, affecting performance.
TTL and Security Considerations
DNS Cache Poisoning
Long TTL values can make DNS cache poisoning more persistent, as malicious records remain cached longer.
Mitigating Security Risks
- Regular Updates: Keep DNS records updated and monitor for unauthorized DNS changes.
- Appropriate TTL Values: Use TTL values that balance performance and security needs.
Leave a Reply