# How DNS Resolution Works:-

When we open a website in our browser, we type a name like [`google.com`](http://google.com), not a numeric IP address. Yet computers can only communicate using IP addresses.

So how does our system figure out that [`google.com`](http://google.com) should connect to something like `142.250.x.x`?

This translation process is called **DNS resolution**.

Think of **DNS** as the **Internet’s phonebook**:  
we know the name, **DNS** finds the **number**.

## What is DNS and Why Name Resolution Exists:-

**DNS (Domain Name System)** is a distributed database that maps human-friendly domain names to machine-friendly **IP** addresses.

**Without DNS:**

* You would need to remember IPs for every website.
    
* Changing a server IP would break bookmarks and links.
    

**With DNS:**

* Names stay the same even if servers change.
    
* The internet scales because the system is distributed, not centralized.
    

DNS is organized in layers, forming a hierarchy:

```plaintext
Root → TLD → Authoritative
```

Our computer normally asks a **recursive resolver** (often provided by your ISP or a public DNS like 8.8.8.8) to do the hard work of walking through these layers.

## Meet `dig`: A Tool to Inspect DNS:-

`dig` (Domain Information Groper) is a command-line tool used to manually query DNS servers.

It lets us see:

* Which name servers are responsible for a domain
    
* How DNS answers are discovered step by step
    
* What records (A, NS, MX, etc.) exist
    

Instead of trusting our recursive resolver blindly, `dig` lets us watch the resolution process.

## The DNS Hierarchy:-

DNS works like asking for directions in stages:

1. Ask the **root**: “Who knows about `.com`?”
    
2. Ask the **TLD (.com) servers**: “Who knows about [`google.com`](http://google.com)?”
    
3. Ask the **authoritative server**: “What is the IP for [`google.com`](http://google.com)?”
    

## Step 1: `dig . NS` → Root Name Servers

```plaintext
dig . NS
```

This asks: *“Who are the name servers for the root zone?”*

We’ll see results like:

```plaintext
a.root-servers.net.
b.root-servers.net.
...
m.root-servers.net.
```

These are the top of the DNS hierarchy.  
They don’t know website IPs, but they know which servers handle each TLD (`.com`, `.org`, `.net`, etc.).

This is the starting directory of the internet.

---

## Step 2: `dig com NS` → TLD Name Servers

```plaintext
dig com NS
```

Now we ask the root (or our resolver):  
*“Which servers are responsible for* `.com` domains?”

The answer will be name servers like:

```plaintext
a.gtld-servers.net.
b.gtld-servers.net.
...
```

These TLD servers don’t know the IP of any website either.  
But they know which authoritative servers manage each `.com` domain.

---

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

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

This asks the `.com` TLD servers:  
*“Which servers are authoritative for* [`google.com`](http://google.com)?”

We’ll see something like:

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

These are the **authoritative name servers** for the domain operated by Google.

Only these servers have the final, official DNS records for that domain.

This is where the real answers live.

---

## Step 4: `dig` [`google.com`](http://google.com) → Full Resolution

```plaintext
dig google.com
```

This performs a full lookup for the default record type .

The recursive resolver will internally do:

1. Ask a root server → get `.com` TLD servers
    
2. Ask a `.com` TLD server → get [`google.com`](http://google.com) authoritative servers
    
3. Ask an authoritative server → get the IP address
    

Finally we receive something like:

```plaintext
google.com.   300   IN   A   142.250.72.14
```

That IP is what our browser connects to.

## Full DNS Resolution Flow:-

Real browser request flow:

1. The browser asks our OS for [`google.com`](http://google.com)
    
2. OS asks the recursive resolver
    
3. Resolver queries:
    
    * Root → TLD → Authoritative
        
4. Resolver returns the IP to our browser
    
5. The browser connects to that IP via TCP/HTTPS
    

## What NS Records Represent:-

An **NS record** says:

> “This server is responsible for answering questions about this domain.”

They are critical because they:

* Define delegation between **DNS** layers
    
* Enable distributed ownership of domains
    
* Allow redundancy (multiple NS for reliability)
    

Without NS records, the chain of trust and lookup would break.

## Recursive Resolver: The Silent Worker:-

Normally, our machine doesn’t contact root or TLD servers directly.

Our **recursive resolver**:

* Performs the multi-step lookup
    
* Caches results to speed up future requests
    
* Hides the complexity from our applications
    

So when we run plain `dig` [`google.com`](http://google.com), we’re seeing the final result of this behind-the-scenes process.

## Mapping `dig` Commands to Lookup Stages:-

| **Command** | **What we Learn** | **DNS Layer** |
| --- | --- | --- |
| `dig . NS` | Who runs the root | Root |
| `dig com NS` | Who runs `.com` | TLD |
| `dig` [`google.com`](http://google.com) `NS` | Who owns the domain | Authoritative |
| `dig` [`google.com`](http://google.com) | Final IP address | Full resolution |

Running them in this order builds a mental model of how the internet finds any domain.

---

## From DNS to Real Browser Traffic:-

When we type a URL:

1. DNS gives the IP
    
2. Our browser opens a TCP connection to that IP
    
3. HTTPS and HTTP requests begin
    

If DNS fails, nothing else can start.

That’s why DNS is often called the **first hop of every internet request**.

---

## Summary:-

* DNS is a layered, distributed naming system.
    
* Resolution walks: **Root → TLD → Authoritative**.
    
* `dig` lets us observe each stage directly.
    
* NS records define who is responsible for each zone.
    
* Recursive resolvers perform and cache lookups for us**“A beginner-friendly, step-by-step guide to how the internet turns domain names into real server addresses using DNS and dig.”**.
    
* Every browser request begins with DNS resolution
