Skip to main content

Command Palette

Search for a command to run...

How DNS Resolution Works

Published
3 min readView as Markdown

What is DNS, and why Name Resolution exists

Computers don’t understand any name that we search in the URL bar, it understands only IPs but where to get the IPs when people only search for names of websites.

That’s where DNS, or Domain Name System, comes in. It is the phonebook of the internet, and it knows whom to call next when someone queries for something in the browser. The process of translating a name into their specific IPs is called Name Resolution.

If there was no DNS, then you would have to maintain your personal database just like we used to do with phone numbers before mobile phones became popular. It also allows to change the IP of the resource without changing the address of the website.

What is the dig command and when it is used

DIG or Domain Information Groper is a network administration command-line tool for quering DNS name servers. Its uses are

  • Troubleshooting DNS problems

  • Verify where the mail is being routed

  • Understand the path a request takes through the DNS hierarchy

Basically, whenever you are facing an issue with your site, just dig it and if you want to check whether your records are set or not, then dig those records on your website, and you will find out.

Understanding how the DNS works

To understand how the DNS works, we will go step by step and understand each dig command

Step 1: The root of the internet

Command - dig . NS

When we search for any address, even though we don’t use ‘.’ at the end of the address the browser automatically parses the name with a ‘.’ at the end. For eg. when we search www.google.com The browser puts a ‘.’ at the end and searches for www.google.com. this ‘.’ is the root of the internet.

When we dig . NS it results in all the root servers on the internet and there are a total of 13 logical root servers. These root servers doesn’t know where google.com resides but definitely knows who handles .com, .org, .net, etc.

Step 2: The Top Level Domain (TLD)

Command- dig com. NS

You will get a result containing all the servers ending with .com and these are all Top Level Domain NameServers. Quering this still doesn’t give us the exact IP of the address but knows which server has the authority to handle the specific address that you are looking.

Step 3: The Authoritative Server

Command: diggoogle.comNS

Now we are querying that ‘Who handles google.com Specifically?’ and we get a result where we see names like ns1.google.com and ns2.google.com. These are the authoritative servers that the owner of the google.com has configured himself. You will find the A record of google.com in these authoritative servers.

Now you know how a DNS is resolved.

Understanding dig google.com and the full DNS resolution flow

When we query dig google.com then your computer’s recursive resolver does all the above steps automatically.

Question: What is the IP of the google.com?

Result:

;; ANSWER SECTION:
google.com.    300    IN    A    142.250.190.46

To get this result the OS resolver asks recursive resolver to do the recursive query. It looks for the cache. If the result is present then good otherwise, it will query for the root server followed by the top-level domain, and finally the authoritative nameserver to get the result 142.250.190.46 after getting this result browser does the http request to this IP and load the webpage.