# How DNS Resolution Works

## **What is DNS and why name resolution exists**

### **DNS**

* DNS Means Domain Name System
    
* It is like an internet phone book, used to translate human friendly domain names to machine readable ip address like `192.168.32.72`
    
* It is a distributed network of servers (root, TLD and authoritative) that work together to find the correct IP address of a domain
    

### **Root vs TLD vs Authoritative servers**

* **Root Server:** This is the highest level in the DNS hierarchy represented by the dot (.), which knows where to find the servers for all TLDs (like .com, .org)
    
* **Authoritative Server:** Holds the actual DNS records (like IP address) for a specific domain and provides the definitive answer(IP address) to a query
    
* **TLD Server:** Manages specific domain extensions like (.com, .net, .uk) and directs queries to the correct authoritative servers for domains with in that extension
    
    ![](https://substackcdn.com/image/fetch/$s_!P_Ol!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0a1bb2c-a1bc-40ce-abde-6fb9d2a66ce8_1600x570.png align="left")
    

### **Why Name resolution exists**

* **Usability:** Humans remember names, not numbers, DNS allows you to use `www.amazon.com` instead of string of numbers
    
* **Scalability:** As the internet grew, a manual system of the text become unmanageable, DNS provides a standardised, distributed solution for a massive network
    
* **Efficiency:** it uses caching to store frequently used address locally, to reduce network load for future requests
    
* **Foundation of Internet:** without it, accessing websites, emails and online services would be incredibly difficult as you need to know the IP address of every server.
    

## **What is the dig command and when it is used**

* `dig` (Domain Information Groper)
    
* It retrieves information about the DNS Servers.
    
* Mostly network administrators use it to verify and troubleshoot DNS problems and perform DNS lookups.
    

### `dig google.com`

Performs a standard lookup for google.com

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262025129/e8ee6cd8-fc7e-44b0-96d9-b6326ec9d664.jpeg align="center")

`dig google.com +short`

Provides a concise answer, showing the IP address

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262041387/d597ace2-82d9-4807-8ac5-bccf58154d82.jpeg align="center")

`dig google.com MX`

Queries for mail exchange (MX) records

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262230040/35770982-560d-4881-9aaf-39d3903324a0.jpeg align="center")

`dig @8.8.8.8 google.com`

Queries google’s public DNS server directly

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262171729/1a5a633a-fa99-4b42-872d-676ebd4f5e86.jpeg align="center")

## **Understanding dig . NS and root name servers**

### Root Name Servers

* These are authoritative DNS Servers that serve at the top level of DNS hierarchy
    
* They do not know the IP address of `www.google.com` but they know which top level domain (TLD) servers handle specific extensions like `.com`, `.org`, `.in`
    
* There are only 13 root name servers all over the world.
    
* While there are 13 IP addresses, there are hundreds of physical servers worldwide using Anycast routing to ensure fast, reliable responses.
    

### NS

* NS means Name Server, a fundamental type of DNS record that identifies which DNS servers are authoritative for a domain
    
* It specifies which server is in-charge of managing the DNS zone file for a domain
    
* It enables the delegation of a domain to specific DNS provider like cloud-flare, AWS, GoDaddy
    

### Why NS Records Matter?

* NS Records are essential for the proper functioning of the internet, without them users can not access websites and emails
    
* **Website Accessibility:** NS records tell browsers where to find the IP address
    
* **Redundancy and Reliability:** it’s a best practice to have multiple NS records (primary, secondary).  If one NS fails, the other can takeover and resulting no down time
    

### `dig .NS`

* `dig`**:** Domain information groper
    
* `dot(.)`: Represents the root zone of the DNS hierarchy
    
* `NS`**:** to list the authoritative name servers which are responsible for root zone.
    
* You will see the list of 13 root server names
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262463834/1b1c492e-ad73-4d8a-867f-cc99c15696a5.jpeg align="center")

## **Understanding** `dig com NS` **and TLD name servers**

This is used to query the authoritative name servers responsible for the top-level domains (TLD’s)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262508655/e687c169-cb5b-4ed7-90a8-dad25d9e9537.jpeg align="center")

## **Understanding** `dig google.com NS`

This looks up the name servers for a specific domain `google.com`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262605205/dc3de7aa-7dad-4f56-8c1b-3402520478ab.jpeg align="center")

## **Understanding** `dig google.com` **and the full DNS resolution flow**

* If you request `google.com` in browser, then it will check in cache, if not found then it will ask for other root name servers
    
* Then Root name servers will says, I do not know `google.com` but you can ask for `.com` TLDs
    
* Then request goes to TLD servers where you will get the response with the addresses of authoritative name servers (eg: `ns1.google.com`, `ns2.google.com`)
    
* Then the query goes to authoritative name servers, this server holds the actual DNS records for `google.com` (A record)
    
* Then Recursive resolver receives the IP, caches it and return the data
    
* Then your device receives the IP and your browser connects to that IP.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262747621/6e929411-1713-4e5e-b309-928b5c299d8a.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769262784588/515c4793-6fe6-4b1d-892d-2d147fcf9e1d.webp align="center")
