Skip to main content

Command Palette

Search for a command to run...

How DNS Resolution Works

Updated
4 min read
How DNS Resolution Works

DNS stands for Domain Name System. Before understanding the working of DNS, let me tell you what actually this DNS Means. In the real world, when a user tries to browse a website, that user tries to put some kind of domain, in our case, assume that was google.com.

The Problem:

When we put a website on the internet, I need to put those files over the server so that the server can serve them to the user. now in a server, we actually get an IP address where our serveris located.
But here the main issue is when how the browser knows where our requested domain server IP.

DNS (Domain Name System)

Here, DNS comes into the picture. Browser somehow reach to the DNS server then the DNS is actually tell the browser of the Actual IP address of the server. Before making a deep dive into these DNS workings, you must have an understanding of the Internet and the network.

How DNS Works?

When a user enter the url of an webiste like google.com, first that requeted is taken by the browser and then browser make a call to the dns resolver.

Recursive DNS resolver

DNS, a resolver is a server. When a browser request some domain to the DNS resolver, the main internal target of this DNS resolver is to find the A record of the Domain. It takes the allthe headache of finding the IP of the requested domain and return back to the Browser.

To do that, it takes multiple steps recursively; that way, it is also known as Recusive DNS resolver.

Let's try to understand the Working of it.

Root Server:

In the world, we have a total of 13 root server, these server are responsivble for the TLD (Top Level Domain). Mean we have multiple DNS provider cloudflare, Google DNS providers, Cloudflare, Google DNS, etc., and we have multiple top level domain, example .com, .in, .or,g etc

TLD server

In the real world, there is the TLD ( Top Level Domain server). It is responsible for which autorative server is actually storing that Top Level domain it return that authoritative server to the dns resolver. Means, it tell the dns resolver which is the autoratativer server for .com for that request.

Authoritative Server

When the DNS resolver got the authoritative server location, it again sent a request to that authoritative server with the user-requested domain, it like saying, “Hey, did you know the A record of this doamin”
and the authoritative server says” yes.”
Then it returns the A record to the DNS resolver, and the DNS resolver then sends back the A record ip to the browser.

What is the Dig command

Now, let’s see everything in real life using the Dig command

Dig is a command-line tool that helps to get Domain Information. The full form of Dig is "Domain Information Groper".

Example

# Command
dig google.com

# Output
; <<>> DiG 9.16.1-Ubuntu <<>> google.com
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57166
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;google.com.                 IN      A

;; ANSWER SECTION:
google.com.          263     IN      A       142.251.43.174

;; Query time: 16 msec
;; SERVER: 127.0.0.11#53(127.0.0.11)
  • status: NOERROR → lookup success

  • A record → IPv4 address

  • 142.251.43.174 → IP of google.com

  • SERVER: 127.0.0.11 → your system asked a local DNS resolver (like Docker/OS stub)

  • rd ra

    • rd recursion desired

    • ra recursion available
      meaning your resolver did all the steps for you.

Understanding dig . NS and Root Name Servers

# Command
dig . NS

# Output
.  518400  IN  NS  a.root-servers.net.
.  518400  IN  NS  b.root-servers.net.
.  518400  IN  NS  c.root-servers.net.
...
.  518400  IN  NS  m.root-servers.net.
  • . (dot) means root zone

  • Root servers are the top of the DNS hierarchy

  • Root servers don’t know google.com IP

  • they only tell: “ask .com servers”

Understanding dig com NS and TLD Name Servers

dig com NS
com.  172800  IN  NS  a.gtld-servers.net.
com.  172800  IN  NS  b.gtld-servers.net.
com.  172800  IN  NS  c.gtld-servers.net.
...
com.  172800  IN  NS  m.gtld-servers.net.
  • .com is a TLD

  • These servers are responsible for telling:

  • which authoritative name servers hold google.com

Understanding dig google.com NS and authoritative name servers

# Command
dig google.com NS

# Output
google.com.  172800  IN  NS  ns1.google.com.
google.com.  172800  IN  NS  ns2.google.com.
google.com.  172800  IN  NS  ns3.google.com.
google.com.  172800  IN  NS  ns4.google.com.
  • These are authoritative servers

  • They contain the actual DNS records of google.com

  • Final A record comes from these servers

Final Flow Should Look like this