Skip to main content

How DNS Resolution Works

Published 6 min readMarkdown
How DNS Resolution Works

When we type a particular website and actually hit enter, how does the internet find the website?

In the previous blog, DNS Record & its Types we learned what DNS records are and why they exists. Now lets find out and understand how DNS resolution actually works, the journey of what exactly happens behind the browser.

DNS Recap: The Internets PhoneBook

DNS(Domain Name System) Exists because:

  • Humans remember names (example.com)

  • Computers communicate using numbers (IP addresses)

DNS is the system that translates (resolves) a domain name into IP address. But DNS does not live in one place, It is distributed everywhere

The DNS Hierarchy

No single server knows everything, each level only knows who to ask next.

There are 4 DNS servers involved in loading a webpage.

  1. DNS recursor: The recursor can be thought of as a librarian who is asked to go find a particular book somewhere in the library. The DNS recursor is a server designed to receive queries from client withe the help of web browsers.

  2. Root Nameserver: The root server is the first step in translating human readable host names(example.com) into IP addresses. It can be thought of like an index in a library that points to different racks of books, typically it serves as a reference to other or more specific locations.

  3. TLD nameserver: The top level domain server (TLD) can be thought of as a specific rack of books in a library. This nameserver is the next step in search for a specific IP address, and it hosts the last portion of a hostname(In example.com, the TLD is “com”)

  4. Authoritative nameserver: This final nameserver can be thought of as a dictionary on a rack of books, in which a specific name can be translated into its definition. The authoritative nameserver is the last stop in the nameserver query. If the authoritative name server has access to the requested record, it will return the IP address for the requested host name back to the DNS recursor (the librarian) that made the initial request.

What are the steps in a DNS lookup?

For most situations, DNS is concerned with a domain name being translated into the appropriate IP address. To learn how this process works, it helps to follow the path of DNS lookup as it travels from a web browser, through the DNS lookup process, and back again. Let’s go through these steps:

Note: Often DNS lookup information will be cached either locally inside the querying computer or remotely in DNS infrastructure. There are typically 8 steps in DNS lookup. When DNS information is cached, steps are skipped form the DNS lookup process which makes it quicker.

The 8 steps in a DNS lookup

  1. A user types ‘example.com’ into a web browser and the query travels into the internet and is received by a DNS recursive resolver.

  2. The resolver then queries a DNS root nameserver (.).

  3. The root server then responds to the resolver withe the address of Top Level Domain (TLD) DNS server (such as .com or .net or .in), which stores the information for its domains. When searching for example.com, our request is pointed toward the .com TLD.

  4. The resolver then makes a request to the .com TLD.

  5. The TLD server then responds with the IP address of the domain ‘s nameserver, example.com

  6. Lastly, the recursive resolver sends a query to the domain’s nameserver.

  7. The IP address for example.com is then returned to the resolver from the nameserver.

  8. The DNS resolver then responds to the web browser with the IP address of the domain requested initially.

Once the 8 steps of the DNS lookup have returned the IP address for example.com, the browser is able to make the request for the webpage.

  1. The browser makes a HTTP request to the IP address.

  2. The server at the IP returns the webpage to be rendered in the browser.

dig command

dig (Domain Information Groper) is a command line tool used to:

  • Inspect DNS records

  • Debug DNS issues

  • Understand how name resolution works

We can think of dig as:

“Show me how DNS answers this question”

dig NS - Root Name Servers

dig . NS

What this command does:

“Answers who is responsible for the root of DNS?”

What we can see:

A list of root servers like:

  • a.root-servers.net

  • b.root-servers.net and soo on….

What this means:

DNS Root (.) → Knows where .com, .org, .net, .ai live exactly

Root servers dont know where google.com is located, They only know:

  • “Ask the .com servers next”

Root Servers are the starting point of all DNS resoultion.

dig com NS - TLD Name Servers

Now we move one level down

dig com NS or dig org NS

dig org NS

What this asks:

  • “Who manages domains under .com?”

  • “Who manages domains under .org?”

What we can see:

For .com server

  • a.gtld-servers.net

  • b.gtld-servers.net

For .org server

  • b2.org.afilias-nst.org

  • d0.org.afilias-nst.org

What this means:

.com TLD Servers → Know who manages google.com, example.com etc

TLD servers dont know the IP address, They only know the authoritative name servers.

dig google.com NS - Authoritative Name Servers

Now we ask for a specific domain.

  • dig google.com NS

  • dig example.com NS

What this asks:

  • “Who is the authoritative for google.com?”

  • “Who is the authoritative for example.com?”

What we can see:

For google.com

  • ns1.google.com

  • ns2.google.com

For example.com

  • elliott.ns.cloudfare.com

  • hera.ns.coudfare.com

What this actually means:

Authoritative Servers → Contains actual DNS record for google.com or example.com

There servers:

  • Store A, AAAA, MX, TXT records, which gives the final answer.

dig google.com - Full DNS Resolution

Now the main question

dig google.com

What this asks:

“What is the IP address of google.com?”

What we can see:

google.com. 279 IN A 142.251.43.14

Now the DNS resolution is complete.

Mapping dig Commands to DNS Layers

  • dig . NS → Root Servers

  • dig com NS → TLD Servers

  • dig google.com NS → Authoritative Servers

  • dig google.com → Final IP address

Each command reveals one layer of the system.

Why NS records are IMP

NS records answer a critical question,

  • “Who should I trust for this domain?”

Without NS records:

  • The whole DNS breaks

  • Domains become unreachable

  • Entire website might disappear

A Real Browser request

When we type https://google.com in the url of browser and hit enter:

  1. Browser asks the recursive resolver

  2. Resolver follows root → TLD → authoritative

  3. IP address is returned

  4. Browser open TCP/TLS connection (Discussed in other blog)

  5. Website loads

DNS resolution is the first step in this whole req res process.

Conclusion

Now understanding DNS resolution isnt just a theory but its interesting that how many events take place for just a website to be load in the browser

DNS helps us in:

  • Debug production issues

  • Design reliable systems

  • Understand how the internet actually works

If DNS is the internets phonebook, them dig is how you read the index.

About the author

  • the topics and concepts which i learn and get more fascinated i write about them here...

No comments yet. Be the first to comment.