# How DNS Resolution Works

1. What is DNS and why name resolution exists?
    
    Computers don't understand names like [`google.com`](http://google.com); they only understand **IP addresses** (like `142.250.190.46`).  
    **DNS (Domain Name System)** is the internet’s phonebook. It exists so you don't have to memorize thousands of number strings. **Name Resolution** is the actual process of turning that human-readable name into a machine-readable IP address so your browser knows exactly which server in the world to talk to.
    
    *In real world example lets consider:*
    
    **Imagine** you want to call your friend ABC, but you only know name, not the phone number. You look it up in a phonebook to find their number, then dial it.
    
    **DNS works the same way:**
    
    * You type [`google.com`](http://google.com) in your browser (the name)
        
    * DNS finds the actual server's IP address like `142.251.41.14` (the phone number)
        
    * Your browser connects to that IP address
        
    
    Without DNS, you'd have to memorize IP addresses like phone numbers!
    
    ```plaintext
    ┌─────────────────────────────────────────┐
    │     ROOT NAMESERVERS (Layer 1)          │
    │  "I don't know google.com,              │
    │   but ask the .com person"              │
    └─────────────────────────────────────────┘
                        ↓
    ┌─────────────────────────────────────────┐
    │   TLD NAMESERVERS (Layer 2)             │
    │   (.com, .org, .edu managers)           │
    │  "I don't know google.com,              │
    │   but Google Inc. does"                 │
    └─────────────────────────────────────────┘
                        ↓
    ┌─────────────────────────────────────────┐
    │  AUTHORITATIVE NAMESERVERS (Layer 3)    │
    │  (Google's own DNS servers)             │
    │  "google.com? That's 142.251.41.14"     │
    └─────────────────────────────────────────┘
    ```
    
2. What is the `dig` command and when it is used?
    
    `dig` (Domain Information Groper) is a command-line tool used by developers and network engineers to "peek under the hood" of DNS. While your browser does DNS lookups automatically and hides the details, `dig` shows you the raw conversation between your computer and the name servers. It is the ultimate diagnostic tool for when a website isn't loading or a new domain isn't working yet.  
    when we type **dig . NS** in our terminal,
    
    **What happens:**
    
    * We ask: "Root servers, who manages the entire DNS system?"
        
    * It reply: "Here are 13 root servers around the world"
        
    
    **Real-world analogy:** Like asking "Who runs the main phonebook?"
    
3. Understanding `dig . NS` and root name servers
    
    **The Root Servers:** `dig . NS`
    
    The "dot" (`.`) represents the **Root of the internet**.
    
    * **The Command:** `dig . NS`
        
    * **What it does:** It asks for the **Name Servers (NS)** that manage the very top of the hierarchy.
        
    * **The Logic:** There are 13 logical root server clusters globally. They don't know where [`google.com`](http://google.com) is, but they know exactly who is in charge of the `.com` extension
        
4. Understanding `dig com NS` and TLD name servers?
    
    And when we type **dig com NS** in our terminal
    
    **What happens:**
    
    * We ask: "Who manages all .com websites?"
        
    * It reply: "Here are the .com nameservers"
        
    
    **Real-world analogy:** Like asking "Who manages all New York business listings?"
    
    So Once we leave the root, it go to the **Top-Level Domain (TLD)** servers.
    
    * **The Command:** `dig com NS`
        
    * **What it does:** It shows you the servers that manage all domains ending in `.com`.
        
    * **The Logic:** These servers are the authority for the "neighborhood." They don't have the final IP, but they know who bought the domain [`google.com`](http://google.com) and which servers that owner pointed their domain to.
        
5. Understanding `dig` [`google.com`](http://google.com) `NS` and authoritative name servers?
    
    Now on terminal type **dig** [**google.com**](http://google.com) **NS**
    
    **What happens:**
    
    * We ask: "Who manages [google.com](http://google.com) specifically?"
        
    * It reply: "Google's own servers manage it"
        
    
    **Real-world analogy:** Like asking "What's Google's phone number?"
    
    * **The Command:** `dig` [`google.com`](http://google.com) `NS`
        
    * **What it does:** It tells you which servers actually hold the "master file" for Google’s records (e.g., [`ns1.google.com`](http://ns1.google.com)).
        
    * **The Logic:** These are **Authoritative**. Whatever they say is the final law for that specific domain. They provide the actual IP address.
        
6. Understanding `dig` [`google.com`](http://google.com) and the full DNS resolution flow?
    

*Now, coming to final with complete flow will look like:*

When we run a simple `dig` [`google.com`](http://google.com), we see the end result of this entire "Recursive" process.

**The Real-World Step-by-Step Flow:**

1. **Browser:** "Hey, what's the IP for [`google.com`](http://google.com)?"
    
2. **Recursive Resolver (Your ISP):** "I don't know, let me ask the **Root**."
    
3. **Root (**`.`): "I don't know Google, but here are the **.com TLD** servers. Go ask them."
    
4. **TLD (**`.com`): "I don't have the IP, but here are Google’s **Authoritative** servers. They know everything."
    
5. **Authoritative Server:** "The IP you want is `142.250.190.46`. Here you go!"
    
6. **Recursive Resolver:** Passes the IP back to your browser and **caches** (remembers) it for a while so it doesn't have to go through all those steps again for the next user.
    

```plaintext
dig google.com

Output shows:

google.com.             299     IN  A       142.251.41.14

Real-world analogy: Like finally getting ABC phone number: 555-1234
```

***Now, lets understand on System Design oriented:***

For a backend developer or DevOps engineer, **NS Records** are critical. If you buy a domain on GoDaddy but want to host your site on AWS, you change your **NS records** at GoDaddy to point to AWS servers. This tells the entire internet: "Don't ask GoDaddy for my IP; ask AWS, because they are the new authority for my domain."

## A final complete DNS resolution would look like;

```plaintext
YOUR BROWSER
    ↓ (types google.com)
┌─────────────────────┐
│ Recursive Resolver  │  (usually your ISP's DNS)
│ (does all the work) │
└─────────────────────┘
    ↓ asks
┌─────────────────────┐
│  Root Nameserver    │  "Where is .com?"
└─────────────────────┘
    ↓ answers
┌─────────────────────┐
│  TLD Nameserver     │  "Where is google.com?"
└─────────────────────┘
    ↓ answers
┌─────────────────────┐
│Authoritative Server │  "It's 142.251.41.14"
└─────────────────────┘
    ↓ returns answer
YOUR BROWSER connects to 142.251.41.14 ✓
```
