The domain name system, or DNS, is a networking system that translates human-friendly names to IP addresses. It is what enables you to point your browser at, say, example.net rather than 22.214.171.124. This article looks at how DNS resolution works and how you can speed up or bypass DNS resolution.
To translate a domain name to an IP address your system first checks if it already knows the IP address. It does this by inspecting your local hosts file. If the hosts file doesn’t have an entry for the domain your system will next connect to a DNS server. This is the resolver – it is the server that will translate / resolve the domain name.
Usually, your ISP’s DNS servers resolve DNS queries but you can manually change which server is contacted. For instance, some people prefer to use public DNS servers such as those provided by Google (126.96.36.199 and 188.8.131.52) or Cloudflare (184.108.40.206 and 220.127.116.11).
The resolver first looks at the right-most part of the domain – that is, the top level domain. For the domain example.net that is the .net extension. The server will next contact a DNS server that can provide information about .net domains.
The DNS server for .net will return the name servers for the domain example.net. The resolver then uses those name servers to find the IP address for the domain, and if all goes well your browser will show you the example.net website.
DNS servers use caching to speed up DNS resolution. To go back to our example, when we asked the .net DNS server for the name servers of the domain example.net it will first have checked if the information was in its cache.
How long data is kept in the cache depends on a DNS record’s time to live (TTL) value. It is common for DNS records to have a TTL of 14400 (4 hours) or 86400 seconds (24 hours). The value can be lower, and it can be useful change the TTL before you change a DNS record. For instance, if you are going to change the A record for your domain in a few days time then you can change the TTL to 3600 (1 hour).
In theory, lowering the TTL to 3600 ensures that the resolver and DNS servers don’t cache DNS records for you domain for more than an hour. In practice, this may or may not happen. Unfortunately, you will have to allow at least 24 hours for DNS changes to fully propagate. After 24 hours all DNS servers should have updated their cache.
DNS may also be cached locally. Often, viewing your site in a private / incognito browser window will bypass your local cache. If that doesn’t do the trick you could try to clear your local cache:
dscacheutil -flushcachein a terminal window.
As mentioned, before your system connects to a resolver it will check if it already knows the IP address of a domain. You can make use of this by manually adding IP addresses and domain names to your hosts file. This can be useful when you are debugging a DNS issue or when you move a website to another server.
For instance, let’s imagine that your domain name has expired and that the domain registrar has changed the domain’s name servers to effectively make your website unreachable. You can still view your website – and even log in – if you know what your website’s IP address is. You can simply add an entry like this at the bottom of your hosts file:
18.104.22.168 example.com www.example.com
Of course, you would still need to sort out the issue with the domain registration but at least you can access your website again.
Similarly, if you are moving your website to a different server then you can use the hosts file to check if your website works properly on the new server before changing the domain’s DNS. After you have copied the website to the new server you simply add the new IP address to your hosts file. Your browser will then show you the website on the new server rather than the “live” version.
On Windows the hosts file is
C:\Windows\System32\drivers\etc\hosts and on OSX and Linux the file is
/etc/hosts. To edit the file you need admin/root privileges.
If you are migrating a website to Catalyst2 then we can give you a “temporary URL” which you can use to view your website on our servers. This is another way to make sure that your website works properly before you change the DNS for your domain. The temporary URL is simply an alias.
You can also use the website hosts.cx. If you enter the server address (that is the IP address) and the domain name the site will give you a “testing URL”. This service is not run by us, and it seems the testing URL are only valid for about a week.
Note: if you are migrating your website to us, we offer a free migration service. Please contact us if you would like us to take care of the website migration.