What is DNS? Everything you need to understand the Domain Name System
The Domain Name System (DNS) is used to access websites. It works like the internet's phonebook, translating domain names into IP addresses so that devices can connect with each other. In this post, we'll explain how DNS works in a simple, easy-to-understand way.
Contents
- Introduction
- Types of DNS Servers
- DNS Resolvers
- Root Nameservers
- TLD Nameservers
- Authoritative Nameservers
- DNS Record Types
- Wrap Up
- Related Articles
Introduction
Hello, my friend! Welcome to part 2 of my DNS breakdown, where I will be explaining to you how the whole thing actually works!
If you're completely new to this topic then I highly recommend you read part 1 first, as it explains the terminology surround the URL and domains. I'll leave a link in the 'Related Articles' section.
In part 1, I described the DNS as the 'phonebook' of the internet, which is true if you're only interested on how it works at a very high level. However, if you want to understand how it actually works – which I assume you do since you're reading this article – then 'phonebook' is a little too simple. We need an even longer, dumber analogy.
Imagine you found the name you're looking for in a phonebook and, instead of a phone number, it says "I dunno, but I do know a phonebook that might have it...". You then track down this other phonebook only for it to tell you to look inside another phonebook that might have it.
You do this, ad nauseam, with each book you narrow down the search until you eventually find the book that contains the phone number.
Sounds exhausting. Luckily, we have a number of DNS server setup that do the searching for us!
Types of DNS Servers
To demystify how your web browser is able to display websites, you need to understand the various types of DNS servers involved, and how they work. DNS servers come in one of 4 categories:
- DNS Resolvers
- Root Nameservers
- TLD Nameservers
- Authoritative Nameservers
I'm going to walk you through the entire system; we'll talk about the different servers when they become relevant. The end-goal of a DNS query – the request made by the user – is to find the DNS server that has the ip address of the website you are looking for, aka, the final phonebook. Refer to figure 1 for an outline of the entire journey.
So what happens when you enter a URL? Your web browser queries a DNS Resolver...
DNS Resolvers
When you, as the web client, type a URL into your web browser, your machine makes a request known as a DNS query, which is sent to a DNS Resolver. A resolver is usually supplied to you by your internet provider, but there are publicly available ones that you can query.
The first thing the resolver does is check its cache to see if it already has an 'answer' for the request. If it's a cache 'hit' (the ip is in the resolver cache), then the resolver will respond to the web client with the ip address. As illustrated by figure 2, this makes the whole process a lot faster.
If it's a cache 'miss', it will make a request, on your behalf, in a quest to find the server that holds a record of the ip address. The first place the resolver queries is one of the 13 main root nameservers.
Root Nameservers
As you may have guessed, the root nameservers correspond with the root domain. There are 13 types, each with multiple copies – hundreds, in fact – scattered across the globe, and their function is to tell the resolver the location of the TLD nameserver. They're managed by an organisation called Internet Corporation for Assigned Names and Numbers (ICAAN).
Going forward, just think of the nameservers as databases containing records that hold the location of other (name)servers. The root nameservers hold records that contain information on where to find TLD nameservers. Since we're looking for www.example.com, we needs a .com TLD nameserver.
If your website, instead, had a .net extension, then the root nameserver will respond to the resolver with the location of the nearest .net TLD nameserver.
TLD Nameservers
TLD nameservers have records that hold the location of nameservers for a domain that's been registered under it.
The website we are looking for has a .com extension, therefore, the .com nameserver will have a record showing the location of the nameserver for the example.com domain.
The organisation looking after these is a branch of ICAAN, known as Internet Assigned Numbers Authority (IANA). They've organised TLD into two categories.
- Country Code TLDs: TLDs specific to a country or region (.uk, .us, .jp, ...)
- Generic TLD: Non country-specific TLDs (.com, .net, .org, ...)
There is a third category, but nobody uses it so don't worry about it.
The .com nameserver will respond to the resolver with the location of the authoritative nameserver.
Authoritative Nameservers
I found the best way to think of authoritative nameservers (AN) as the server(s) that hold an 'authority' over a particular domain. As in, it's responsible for all the information regarding a domain.
It's an umbrella term because you can think of every DNS nameserver as an AN. The root nameservers is the ANs for the root domain; TLD nameservers are ANs for their respective TLDs.
Nameservers that hold records corresponding to the domain example.com, are ANs for example.com.
Usually, the AN would be the final stop in the resolvers mission to find the ip address. Somewhere in the AN there exists an A (address) record which is the records type that hold the ip address. The AN responds to your resolver with the ip address which is then sent back to the web client. The ip is then used by your internet service provider to find the website. The resolver then caches the ip for future use.
On the other hand, the AN can respond with a CNAME (alias) record. These records contain another hostname. What happens then is the resolver has to resolve a completely different address, so it will need to start the process all over again, starting from the root nameserver.
Take my website for example. If you search for www.wayoftheengineer.com, once the resolver gets to the AN for wayoftheengineer.com, it will obtain an ip address.
However, if instead I had it resolve to a CNAME records that points to a completely different domain, www.InAnotherCastle.org, then the resolver would have to start the entire journey all over again starting from the root nameserver until it finds an ip (poor little resolver).
DNS Record Types
In database terminology, a record is effectively a group of related data. Typically, a DNS record maps one hostname to something else. That 'something else' is determined by the type of record.
The most common are A and CNAME, but it's useful to be aware of the other types. These include, but are not limited to:
- A Records (Address): Maps a hostname to an IPv4 address
- AAAA Records (Quad A): Maps a hostname to an IPv6
- CNAME Records (Alias/Canonical Name): Maps one host name to another.
- A ALIAS Record: Maps a root domain to another root domain. Typically, the root domain can only be mapped to an ip. A ALIAS allows you to bypass this.
- NS Record: Maps a domain name to a nameserver
- SOA Record (Start of Authority): Primary nameserver in a zone, hold the administrative information.
- MX Records (Mail Exchange): Points to servers that process email
- SRV Record (Service Record): Locations of specific services on a network
- PTR Records (Pointer): Opposite of A/Quad A, maps an ip address to a hostname.
Wrap Up
That concludes this article, hope you enjoyed it more than the resolver. You should now have a fundamental understanding of the DNS to build your knowledge from.
The whole process is about narrowing down your search, domain by domain, until eventually you find