# How DNS Resolution Works

Since you are here to understand how the DNS Resolution works, you would be aware of what DNS is, but in case you are not completely aware of tit-bits related to DNS, we would be covering that as well, so stick till the very end and by the end, you would have a pretty good knowledge about the topic you have started.

## What is DNS & Why do we need it?

To explain in technical terms DNS (Domain Name System) is the system that translates human- readable domain names into IP addresses.

Now you might not understand what this actually means so let us understand it through an example of contacts in your mobile, you might be aware of your phone number and some of your closed ones but can you remember the phone number of each and every one of your connections or what if one of your connections actually changed their mobile no. so now you need to remember their new way to contact? Pretty hard right? So you do the most logical thing out there, you save the phone numbers by the contact names and when you actually need to contact any one of them, you simply search for the name and you get their phone number, which you copy in your dial or call directly.

DNS works in a similar way, you see `https://example.com` is the domain of a website which must be sitting on some server itself. But unlike humans who are well versed with using words, computers find numbers to be fascinating and keep track of everything in form of numbers itself. So a computer does not know what is `https://example.com` but it surely understands what it needs to do when it gets the IP address for `https://example.com`(93.184.216.34). So to make it easier for humans to remember things through words and not through number patterns, DNS comes to save the day.

So it won’t be wrong to say that DNS is the internet’s phone book.

## What’s DNS resolution?

Since now we know that DNS maps human friendly domain names into machine friendly IP addresses, we need to know what the IP address for a particular domain is, the process of looking for the ip address of a particular website through different servers is called as DNS resolution.

The DNS resolution isn’t a single process, where the system would go and look for the IP address in the server, because it is not like a central database, rather the resolution happens in layers because DNS is a distributed system.

There is a hierarchy of DNS servers through which the DNS resolution takes place:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769573100991/3b9d553b-9f27-46da-afc7-ade64060e49e.png align="center")

**ROOT SERVER → TLD NAME SERVER → AUTHORITATIVE NAME SERVER**

## DIG what?

DIG which stands for domain information groper is a command line tool which is used to query DNS servers, troubleshoot dns problems, or verify dns records.

Programmers use dig because it enpowers them to ask questions like:

* Does this domain exist?
    
* What is its IP address?
    
* Who are its name servers?
    
* Why is DNS failing or timing out?
    

Unlike browsers who carry out the whole DNS process behind the scenes, `dig` helps us to break the process into smaller steps and check what is going on behind the scenes. It is the way we can explore the inner working of a DNS system.

## Understanding Various DIG commands

Now that we are aware of DNS resolution and DIG, it makes sense that we get tn using the dig command.

### dig . NS

The . in the dig . NS command represents the root of the DNS hierarchy. It shows the 13 root servers that are available.

A root server:

* does not know the IP of the website
    
* starting point of every DNS lookup
    
* only knows where to find the TLD servers
    

> Root servers are at the top of the hierarchy

```powershell
dig . NS
```

![Text showing DNS root server names listed from i.root-servers.net to h.root-servers.net under the "ANSWER SECTION."](https://cdn.hashnode.com/res/hashnode/image/upload/v1769570831568/2f3a6dae-a253-4e1c-bae8-2b02f2e64c4e.png align="center")

### dig &lt;TLD domain&gt; NS

`dig <TLD> NS` is used to find the **authoritative name servers for a Top-Level Domain (TLD)**.  
A **TLD (Top-Level Domain)** is the highest level in the DNS hierarchy and represents the category or country of a domain, such as `.com`, `.in`, or `.co`.

These TLD name servers know **which authoritative name servers are responsible for domains under them**.

```powershell
dig in NS
```

![Text display showing a DNS query answer section listing root servers with their corresponding names, such as "i.root-servers.net" and "j.root-servers.net," each associated with "IN NS" and the number "117372."](https://cdn.hashnode.com/res/hashnode/image/upload/v1769571217203/f7d17f4b-d6cd-4758-9ce5-a364a49c5bd4.png align="center")

### dig &lt;domain&gt; NS

The `dig <domain> NS` is used to find the **authoritative name servers for a domain.**

An **authoritative name server** is the DNS server that **officially knows the DNS records for a domain** and gives the **final, trusted answer**.

```powershell
dig chaicode.com NS
```

![A DNS answer section displaying two entries for "chaicode.com" with name servers "elma.ns.cloudflare.com" and "trace.ns.cloudflare.com."](https://cdn.hashnode.com/res/hashnode/image/upload/v1769571641107/779a1cda-6345-4f56-9681-03ec260163b4.png align="center")

## Recursive Resolver

We have learnt the various dig commands and also seen what results they produce, however when we are using a browser we don’t go on to find the IP of a website on our own. All thanks to **recursive resolver** which is a DNS component that **finds the final answer on your behalf** by querying multiple DNS servers until it gets an IP address.

The recursive resolver takes the request from the browser/OS and does the entire walk through the DNS hierarchy.

**What the recursive resolver does:**

* Queries **root servers** to find the TLD
    
* Queries **TLD servers** to find the authoritative server
    
* Queries the **authoritative server** for the IP address
    
* Caches the result for future requests
    

**What the recursive resolver does not do:**

* It does **not** store original DNS records
    
* It is **not** the source of truth
    
* It does **not** host domains
    

> Recursive Resolver task is to resolve

### Where does Recursive Resolver live?

A **recursive resolver** is a DNS server that performs DNS resolution on behalf of a client.  
It usually lives in one of the following places:

* **Your Internet Service Provider (ISP)** — the default DNS resolver provided by your network
    
* **Your router** — many home routers act as a local DNS forwarder/cache
    
* **Public DNS services**, such as:
    
    * **Google DNS** (`8.8.8.8`)
        
    * **Cloudflare DNS** (`1.1.1.1`)
        

## Searching `https://google.com` in browser

The moment you type `https://google.com` in the url and hit enter, your browser looks for the IP in the cached dns that it had stored.

If there is no info in the cached DNS, it handles this job to recursive resolver. The recursive resolver takes and queries for the `root server` which gives the information about the `TLD server` which hold the information about the Top level domain. The TLD server in return return the authoritative server information which consist the information about the website.

![Illustration of DNS resolution flow for "google.com". The process starts with the DNS resolver, checks the DNS cache, then queries root and TLD servers, retrieves the IP address (142.251.42.238), and sends it to the browser, allowing connection to "google.com".](https://cdn.hashnode.com/res/hashnode/image/upload/v1769573468437/34b95a7a-ad16-40f1-a399-a4b6735765bf.png align="center")

Once the IP address is obtained, it is returned to the browser. The browser then establishes a network connection to that IP address using **TCP** and communicates with the server over **HTTPS** to fetch the website.

## Conclusion

DNS is a **distributed, hierarchical system** that translates human-friendly domain names into machine-friendly IP addresses. Instead of relying on a single central database, DNS resolution happens in layers, with the **recursive resolver** doing the heavy lifting by querying root, TLD, and authoritative name servers. Once the IP address is found, the browser can establish a secure connection and load the website—making DNS an essential first step in every internet request.
