# How DNS Resolution Works

### ❀ Introduction :

⤷ Every time you type [**google.com**](http://google.com) in your browser, something important happens in the background.  
Your computer does **not understand website names**. It only understands **IP addresses**.

⤑ DNS (Domain Name System) helps convert:

```plaintext
google.com → IP address
```

⤑ That is why DNS is called the **internet’s phonebook**.

⤑ In this blog, we will understand **how DNS works step by step** using a tool called `dig`.

### ❋ What is DNS and Why Do We Need It?

⤑ Humans like easy names:

* [google.com](http://google.com)
    
* [amazon.com](http://amazon.com)
    
* [github.com](http://github.com)
    

⤑ Computers like numbers:

* 142.250.185.46
    

⤑ Without DNS:

* You would need to remember IP addresses
    
* Websites changing servers would break bookmarks
    

⤑ DNS solves this by:

* Mapping domain names to IP addresses
    
* Working in a **distributed way**, not from one single server
    
* Making the internet **fast, scalable, and reliable**
    

### ❋ What is `dig` and Why Is It Used?

⤑ `dig` stands for **Domain Information Groper**.

⤑ It is a command-line tool used to:

* Check DNS records
    
* Understand how DNS resolution works
    
* Debug DNS problems
    
* Learn DNS deeply
    

Basic command:

```plaintext
dig google.com
```

Unlike browsers (which hide DNS details), `dig` shows **exactly what is happening**.

### ❋ DNS Works in Layers (Hierarchy)

DNS is not one server.  
It works in **three main layers**:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769256793541/78a966a6-cd37-4eec-8721-39e8459311f2.png align="center")

Each layer only knows **the next layer**, not everything.

### ❋ Layer 1 : Root Name Servers (`dig . NS`)

Command:

```plaintext
dig . NS
```

This asks:

Who manages the root of DNS?

**What root servers do:**

* They are the top of DNS
    
* They do NOT know website IPs
    
* They only know where TLD servers are
    

Example response idea:

I don’t know [google.com](http://google.com), but I know who manages `.com`

Important points:

* There are **13 root server names**
    
* They are spread across the world
    
* Very reliable and fast
    

### ❋ Layer 2 : TLD Name Servers (`dig com NS`)

Command:

```plaintext
dig com NS
```

This asks:

Who manages the `.com` domain?

**What TLD servers do:**

* They manage domains like `.com`, `.org`, `.net`
    
* They do NOT know IP addresses
    
* They point to **authoritative servers**
    

Example response idea:

*I don’t know google’s IP, but I know Google’s name servers*

### ❋ Layer 3 : Authoritative Name Servers (`dig` [`google.com`](http://google.com) `NS`)

Command:

```plaintext
dig google.com NS
```

This asks:

*Who is responsible for* [*google.com*](http://google.com)*?*

**Authoritative servers:**

* Are owned by the domain owner (Google)
    
* Store real DNS records
    
* Are the **source of truth**
    

They contain:

* A records (IP address)
    
* MX records (email)
    
* TXT records (verification)
    

Example:

```plaintext
ns1.google.com
ns2.google.com
```

These servers finally know:

*Yes, this is the IP address of* [*google.com*](http://google.com)

### ❋ Full DNS Resolution (`dig` [`google.com`](http://google.com))

Command:

```plaintext
dig google.com
```

This gives:

* IP address
    
* TTL (how long it can be cached)
    
* Which DNS server answered
    

### ⤑ What happens behind the scenes:

1. Check cache
    
2. Ask root server
    
3. Root points to `.com`
    
4. `.com` points to Google servers
    
5. Google server returns IP
    
6. Result is cached
    

TTL example:

```plaintext
300 seconds
```

Means the result can be reused for 5 minutes.

### ❋ What Are NS Records and Why Are They Important?

⤷ **NS (Name Server) records** tell:

* Who controls a domain
    
* Where DNS queries should go next
    

⤑ They are important because:

* DNS is distributed
    
* No single server controls everything
    
* Multiple servers give backup (redundancy)
    

If one server fails, another works.

### ❋ What is a Recursive Resolver?

⤷ Your computer does not talk to root servers directly.

⤑ Instead, it uses a **recursive resolver**, such as:

* 8.8.8.8 (Google DNS)
    
* 1.1.1.1 (Cloudflare DNS)
    
* ISP DNS
    

Flow:

```plaintext
Your PC → Recursive Resolver → Root → TLD → Authoritative
```

⤑ The resolver:

* Does all DNS work for you
    
* Caches results
    
* Returns final IP
    

### ❋ DNS and Real Browser Requests

⤷ When you open a website:

1. Browser checks cache
    
2. OS checks cache
    
3. Recursive resolver is asked
    
4. DNS resolution happens
    
5. IP address is returned
    
6. Browser connects using HTTP/HTTPS
    

⤑ DNS usually takes:

* **20–120 ms** if not cached
    
* **&lt;10 ms** if cached
    

That’s why DNS feels instant.

### ❋ DNS from a System Design View

### ⤑ *DNS is designed to be:*

* Distributed
    
* Fast
    
* Fault-tolerant
    
* Scalable
    

⤑ Important ideas:

* Caching improves speed
    
* Multiple name servers improve reliability
    
* DNS helps CDNs route users to nearby servers
    

### *You can watch for System Design View of DNS :*

<iframe width="560" height="315" src="https://www.youtube.com/embed/27r4Bzuj5NQ?si=UZ5DqYK9k1qU2yYA"></iframe>
