2015-12-16

How does the Domain Name System work?

The Domain Name System is one of the most heavily used services on the internet. Despite this, it is also one of the most invisible. Hidden in plain sight, people use it every day, often in blissful ignorance that they are even doing so, let alone understanding how it works. For many it is the unseen magic of the internet: they type a domain name into the address bar of their browser, and web pages appear after a short wait.

What the majority of internet users don’t know is that behind the scenes their computer is using the DNS system to look up the IP address associated with that domain name, which is required for the computer to communicate with the server and fetch the web page requested. The way the system is designed means that initially the computer checks its own DNS cache first to see if it already knows the IP address that the domain name points to. If it doesn’t then the computer then asks the servers it has configured as DNS resolving servers if they know the IP address. These servers will either respond with the requested information if they already know the answer, or they will then look up the server that is responsible for the records of that domain name and ask that server for the information.

As previously mentioned domain resolving servers and computers keep a cache of any domain records that they have looked up. The purpose of this is to reduce the amount of traffic that needs to be passed around in order for computers to look up domain records, and also reduce load on the domain servers of popular domains. To manage this cache in an optimal fashion, each group of domain records, called a zone, is set with a TTL value, or Time To Live. This essentially provides an amount of time for a server to assume that the record it has cached will be valid for, after which it will need to check the records again. The most common TTL that is used is 86400; the value is in seconds and this equates to 24 hours. Therefore, from the moment a server or computer caches a domain record with that TTL it will regard it as valid for a full day before it will attempt to look it up again.

DNS Propagation is the term used for the act of a change of a DNS record to be cached by the different servers and computers around the internet that may require that information. So with a TTL of 86400 seconds there is a potential wait of up to 24 hours to ensure that all computers across the internet have seen the change that has been made. Now, you don’t need to leave the TTL at the default, and in fact it’s fairly common to adjust the TTL to match the timings that you need. These timings will depend on how often you are happy for your server to be queried for the information, and how often you predict you may be making changes to the DNS records. For most users, though, the default is fine.

There are ways of avoiding this delay though, and if you know you are going to be making a DNS change and wish for all users to see the change at around the same time there are things you can do to make that happen. The first thing is to shorten the TTL, so a day or so before you want to make the change to the record, adjust the TTL to be an hour (3600 seconds). This change of the TTL will also take a day to propagate through the system. So after 24 hours, nearer the time of the change, you can adjust the TTL to a smaller interval such as 5 minutes. Once an hour has passed for that TTL change to propagate you can then either shorten the TTL once more to a smaller value, or make your change to the DNS record. At the same time as changing the record, you can set the TTL back to 86400 for a return to normal service.

Some may ask why they can’t just set the TTL to this lower value to start with and leave it like that. You can and it’s perfectly acceptable, but remember that in doing so you can significantly increase the number of DNS requests that your DNS server then has to respond to, which will have an impact both in terms of system load and the bandwidth usage of your server.

For a range of server administration tips and tricks, be sure to check out The 100TB Blog.

Show more