A Beginner's Guide to DNS: What it is and how it works


Introduction
Ever wondered when you type www.youtube.com on the search bar of your web browser, how does it know to request the Youtube server for the page’s data? 🤔
The answer is DNS - Domain Name System.
Okay, but what is it and how does it work? Before we understand that, we first must understand how this Internet works.
This article will cover the basics of DNS starting with what it is and the role of it, how it works at a high level and finally going a little deep into its working.
So let’s start shall we? 😃
The Internet and how DNS fits into the picture
Every website that lives on the Internet is running on a physical machine (server), maybe it’s hosted on the cloud or bare metal. Now if we want to access these websites we need a way to do that right? That’s where IP address comes in. Think of them as the address to your house. Similarly to identify every computer that is connected on the Internet, it is associated with an IP address. Your computer has it too but others can’t access it since it’s private. That means these servers where websites are hosted have a public IP address where we can go to get the requested resource.
But there is a problem.
You see it’s hard to remember IP addresses. Here are some examples:
Google - 142.250.190.14
Wikipedia - 208.80.154.224
The examples above are IPv4 addresses, today there exists a newer format too: IPv6 which is even longer and complex. Moreover these addresses might differ from time to time due to various factors like load balancers, CDNs etc. but we are ignoring it. Now imagine if we try to remember the IP address of each and every website…*phew* that’s a lot of work.
But it’s easy to remember google.com and wikipedia.org right?
This is exactly where DNS fits into the picture.
What is DNS?
As the name suggests - a DNS (Domain Name System) is basically a server where it keeps a record of all the domains (google.com, facebook.com etc.) on the Internet and their associated IP address. You can think of it as the phonebook of the Internet.
Essentially it resolves a particular domain name to its IP address so that the browser can request the server where the website is hosted. Once your browser receives the desired response from the server it displays the required content which you see.
Congrats! Now you know what happens behind the scenes when you type something on the browser.
But if you are curious (you should be) then read on as we dive deep into its working.
How it works?
This whole process is not as simple as it sounds. There is a lot of work going on behind the scenes. Before that we must understand that there are lots of Public DNS servers available worldwide. Some of the popular ones are - Google DNS 8.8.8.8
, Cloudflare 1.1.1.1
etc. Your ISP Internet Service Provider (ISP) also has their own DNS server. Your computer automatically configures itself to use a particular DNS server when you connect to a network (Wi-Fi or ethernet).
Next, the whole journey starts when you type something on the browser and hit enter. A series of operations take place before you get back the IP of the server where your requested content is hosted.
Let us understand with this diagram:
Let’s say you searched for youtube.com. Your browser requests the public DNS server which is configured on your machine, where it checks if the IP of the requested domain is available in its cache. If it is present, it immediately returns that. If not it continues with its search. These Public DNS servers can be categorized under Recursive Resolvers, meaning, it interacts with other DNS servers to resolve queries on behalf of the client.
The first step of resolving a domain, is the Root Server. It helps to identify the Top Level Domain (TLD) and redirects to the appropriate TLD server. In our case .com is the TLD.
In case you don’t know, for example with: www.youtube.com
:
Top Level Domain:
.com
Second Level Domain:
youtube
Sub-Domain:
www
Therefore TLD servers are responsible for managing the top level domains in the DNS hierarchy, such as .com, .org, .net etc.
The public DNS server queries the Root Server, which doesn’t know the specific address of youtube.com but does know the address of the .com
TLD server. The Root Server then returns the IP address of the .com TLD server.
Essentially, TLD servers act as intermediaries that help narrow down the search.
Next the public DNS queries the TLD server for the address. But it also doesn’t know the address of youtube.com. But what it knows is the IP of the server where the domain lives. It is called the Authorative Name Server. So it returns that.
Authoritative Name Servers are the final stop in the DNS resolution process. They contain the actual address for a specific domain and provide definitive answers to queries about that domain. It is generally the sever of the provider from where the domain was purchased (e.g: GoDaddy, Google Domains etc.)
Finally the public DNS server queries the Authorative Name Server for youtube.com. Once it receives the required address, it returns it to the public DNS. It then caches the address for future requests to the same domain. Once all this is done the address is returned to the browser and it makes the final request to that IP address to get the desired content.
Cool isn’t it?
Now you know what happens behind the scenes when you type something on the browser.
There are more things to know and learn about DNS like records, but I have tried to keep the blog as simple as possible. Hope you learnt something new and if you have reached till here, thanks a lot for reading!
Subscribe to my newsletter
Read articles from Subham Mani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Subham Mani
Subham Mani
Hi! I'm Subham Mani currently pursuing my CS degree at HITK, Kolkata and I build stuff that makes this world a little better place to live. I love participating in hackathons and so far in my journey I have won two of them. I also hold a position as the Web Lead at GDG On Campus HITK where I mentor fellow students on topics related to Web Development.