# How DNS Resolution Works

---

## What Is DNS and Why Name Resolution Exists

Computers don’t understand names like [`google.com`](http://google.com).  
They understand **IP addresses** like `142.250.183.14`.

DNS (Domain Name System) exists to **translate human-friendly names into machine-friendly IP addresses**.

Simple definition:

> **DNS is the internet’s phonebook.**

You remember names.  
Computers use numbers.  
DNS connects the two.

---

## Why DNS Is Needed (Real-World Analogy)

Think of calling someone:

* You search a **name** in your contacts
    
* Your phone finds the **number**
    
* The call connects
    

DNS works the same way:

* You type a **domain name**
    
* DNS finds the **IP address**
    
* Browser connects to the server
    

---

## What Is the `dig` Command

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

It is a **diagnostic tool** used to:

* Inspect DNS resolution
    
* See which name servers are involved
    
* Debug DNS issues
    
* Understand how name resolution works step by step
    

Simple idea:

> `dig` lets you ask DNS questions directly from the terminal.

---

## Where `dig` Fits in the Big Picture

![Image](https://miro.medium.com/1%2A-kCFoSB3-pMwajK6LTJY6Q.jpeg align="left")

![Image](https://substackcdn.com/image/fetch/%24s_%21piIO%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1adddd56-9fb5-4dc4-ad1a-0faea938acf0_2284x2054.png align="left")

![Image](https://www.inetdaemon.com/img/dns-hierarchy.gif align="left")

Browsers do DNS automatically.  
`dig` lets **you see it manually**.

---

## DNS Resolution Happens in Layers

DNS is not one server.  
It is a **hierarchy**.

Order:

1. Root name servers
    
2. TLD name servers (`.com`, `.org`, etc.)
    
3. Authoritative name servers (for the domain)
    

This layered design keeps DNS:

* Scalable
    
* Fast
    
* Reliable
    

---

## DNS Hierarchy (Mental Model)

![Image](https://substackcdn.com/image/fetch/%24s_%21P_Ol%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0a1bb2c-a1bc-40ce-abde-6fb9d2a66ce8_1600x570.png align="left")

![Image](https://cdn.shortpixel.ai/spai/q_lossy%2Bret_img%2Bto_webp/wp-public-fs.s3.ap-south-1.amazonaws.com/tasks/165d58952b1e9854faee9d165e220fad987e31ad63557b/images/602c130c2edd0f001a8d5ed9-65df147eb8c35.jpg align="left")

![Image](https://images.openai.com/static-rsc-3/v7iHjuBYNqVRIO8sGA2khay3jxWvJ-wQK_-u_3UTtvcztya5Ve846LVrhaOfj4drOYlXNwySKiKw87vsxVi99mTSoj1OXp8hdBEHhqgasME?purpose=fullsize align="left")

Each layer answers **only what it knows** and points to the next.

---

## Understanding `dig . NS` (Root Name Servers)

Command:

```bash
dig . NS
```

What this asks:

> “Who are the name servers for the root (`.`) of DNS?”

What you learn:

* These are the **top-level servers**
    
* They don’t know IPs for websites
    
* They only know **where TLD servers are**
    

Key idea:

> Root servers are the starting point of DNS, not the end.

---

## Understanding `dig com NS` (TLD Name Servers)

Command:

```bash
dig com NS
```

What this asks:

> “Who manages the `.com` domain?”

What you learn:

* These servers manage **all** `.com` domains
    
* They don’t know [`google.com`](http://google.com)’s IP
    
* They know **which servers are responsible for it**
    

Key idea:

> TLD servers narrow the search.

---

## Understanding `dig` [`google.com`](http://google.com) `NS` (Authoritative Servers)

Command:

```bash
dig google.com NS
```

What this asks:

> “Which servers are authoritative for [`google.com`](http://google.com)?”

These name servers:

* Belong to **Google**
    
* Contain the **actual DNS records**
    
* Know the real IP addresses
    

Key idea:

> Authoritative servers give **final answers**.

---

## What NS Records Represent (Important)

NS (Name Server) records say:

> “These servers are responsible for this domain.”

Why NS records matter:

* They define **authority**
    
* They enable delegation
    
* They make DNS distributed
    

Without NS records, DNS cannot scale globally.

---

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

Command:

```bash
dig google.com
```

What happens behind the scenes:

1. Resolver asks root servers
    
2. Root points to `.com` servers
    
3. `.com` points to Google’s authoritative servers
    
4. Authoritative server returns the IP address
    

![Image](https://miro.medium.com/1%2AgoSb1oow5UBNF3KkzvOX8A.png align="left")

![Image](https://assets.bytebytego.com/diagrams/0176-dns-look-up.png align="left")

![Image](https://www.researchgate.net/publication/330006223/figure/fig1/AS%3A709642057445377%401546203259697/Domain-resolution-process-with-a-recursive-resolver.ppm align="left")

`dig` shows you the **final answer**, but the resolver already did the full journey.

---

## Recursive Resolver (The Hidden Worker)

Your system uses a **recursive resolver** (ISP, router, or public DNS).

Its job:

* Perform all DNS steps for you
    
* Cache results
    
* Return the IP quickly
    

You rarely see it, but it does most of the work.

---

## Mapping `dig` Commands to DNS Lookup Stages

![Image](https://miro.medium.com/v2/resize%3Afit%3A1268/1%2AXqr7YdkgKF-MGr0jKGTpMg.jpeg align="left")

![Image](https://miro.medium.com/0%2AZsNeyyEN9O6-ZKC4 align="left")

![Image](https://miro.medium.com/1%2A-kCFoSB3-pMwajK6LTJY6Q.jpeg align="left")

| Command | DNS Layer |
| --- | --- |
| `dig . NS` | Root servers |
| `dig com NS` | TLD servers |
| `dig` [`google.com`](http://google.com) `NS` | Authoritative servers |
| `dig` [`google.com`](http://google.com) | Final resolution |

---

## Connecting This to Browser Requests

When you type [`https://google.com`](https://google.com):

1. Browser asks the OS for IP
    
2. OS asks recursive resolver
    
3. DNS resolution happens
    
4. Browser connects to the IP
    
5. HTTP request starts
    

DNS **always comes before HTTP**.

---

## Practical Takeaways

* DNS is a **distributed lookup system**
    
* Resolution happens in **layers**
    
* `dig` helps you see each layer clearly
    
* NS records define **who is responsible**
    
* Browsers hide this complexity, but it still happens
    

---

## Final Reassurance

You do **not** need to remember:

* Server names
    
* Output formats
    
* All record types
    

If you understand:

> **Root → TLD → Authoritative → IP**

You already understand DNS better than most beginners.

---
