# How DNS Resolution Works

So, for us connect to any machine on the internet , we need its IP address. But as the Human being how can we remember the IP address of the machine and there are n number of machines each company has its own servers/ machine where the application is hosted.  
  
We can remember `www.google.com` more comfortably rather than this `20.142.202.15` IP address.

In this article, we explore how this domain name (www.google.com) and IP address ( 20.142.202.15) mapping actually works.

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

DNS is not a single machine; it’s a global collection of hierarchal system of servers to resolve each part of the namespace.

* For many reasons IP address of a site can change. However, the site name remains the same, so you don’t have to look for a new URL with every change.
    
* Billions of sites and DNS resolve them in a distributed system, not a single server.
    

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

Understanding DNS requires some real world example. Domain Information Groper (`dig`) is a DNS diagnostic command line tool used to inspect name servers, query DNS records, and debug DNS issues.

The `dig` command shows raw DNS response, very useful for learning.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769544457341/7b35b631-ef4a-4190-ae47-6b1a164fccbd.png align="center")

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

`.` means the root server and `NS` looks for name server records. But these servers do not know the IP addresses of domains. Name servers know which TLD servers to ask next.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769545396708/6526a51b-eb4e-4954-b494-e13194da7f41.png align="center")

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

This is where you find the **Top Level Domain** (TLD). It’s like you’re asking *who manages the .com domains?*

You get .com TLD name servers like [**a.gtld-servers.net**](http://a.gtld-servers.net)[,](http://a.gtld-servers.net/) [**b.gtld-servers.net**](http://b.gtld-servers.net) [as a response.](http://b.gtld-servers.net/) These servers know which authoritative servers maintain .com domains[, but you won’t ge](http://a.gtld-servers.net/)t [IP addresses.](http://b.gtld-servers.net/)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769546095709/daec1c87-3740-459f-bd8e-e608bc62e774.png align="center")

## Understanding `dig` [`google.com`](http://google.com) `NS` and authoritative name servers

This is where we get clost to the IP address.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769546268216/b8c2bd05-2348-4193-9aab-419ceee00932.png align="center")

these four are the Name servers of the google and if we want to get the actual IP address on the the google server is hosted, then we need to use the `dig google.com` command

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769546182236/1bbc4836-ddd7-4da1-94c5-8b953689cbe1.png align="center")

## Understanding `dig` [`google.com`](http://google.com) and the full DNS resolution flow

Here the A record means that this is the actual IP address of the server and 177ms shows the TTL (time to live) means after this time the cached values refresh.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769546396609/39a91457-4959-4d80-862a-9024f317a8f5.png align="center")

## Conclusion

The below diagram shows the complete flow, form how the domain name mappeing works with all the Authoritative Name servers , Root Servers and the Top level domains servers.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769545289287/fbf2ac5e-6774-4d7b-b6de-77cf72a83885.png align="center")
