DEV Community

Cover image for How DNS Works: A Browser’s Journey from Domain to IP
Kunal
Kunal

Posted on

How DNS Works: A Browser’s Journey from Domain to IP

Before we start , I strongly recommend you to read this blog 👇

This above blog will tell you about What DNS is and what are DNS records ?


In this blog we will discuss :

  • What is DNS and why name resolution exists ?
  • What is the dig command and when it is used ?
  • Understanding dig . NS and root name servers
  • Understanding dig com NS and TLD name servers
  • Understanding dig twitter.com NS and authoritative name servers
  • Understanding dig twitter.com and the full DNS resolution flow

DNS : Domain Name System

👉 DNS stands for "Domain Name System" it converts a hostname such as ( www.example.com ) into a computer friendly IP address such as ( 192.168.1.1 )

Why name resolution exists ?

Humans can memorize the names easily such as ( Twitter.com )
Computer understands the Numbers more ( 192.8.1.1 )

So this name resultion act as a translator between humans and machine .


Dig Commands

Dig stands for "Domain Information Groper" . It is use when we want to retrieves information about DNS servers .

When it is used ?

Dig commands used by adminisatrators .
It is use to verify and troubleshoot DNS problems and perform DNS lookups.

Syntax

dig [server] [name] [type]
Enter fullscreen mode Exit fullscreen mode

Understanding commands

lets suppose you write ( www.twitter.com ) in your browser .

So how does your browser reach .

1. Root Nameservers

Root nameservers are the starting point of the DNS .

There are only 13 logical root server but one has many physical copy worldwide .

It does not know where the IP is but it know where to send browser next to find the IP .

So , Root servers guide the browser saying this domain belongs to .com ask TLD where this .com belongs .

You can also check all the 13 logical root server .

dig . NS
Enter fullscreen mode Exit fullscreen mode

This command will return the root servers .

root

2. TLD Nameservers

TLD stands for Top level domain server that handles .com ,.net ,.in

There are multiple TLD servers for each domain .This server again does not return IP address

You can also check TLD nameserver of a domain .

dig com NS
Enter fullscreen mode Exit fullscreen mode

This returns the authoritative name servers for the .com TLD.

tld

Now the resolver knows exactly who to ask. It picks one authoritative name server

3. Authoritative Nameservers

Now we know that we have a list of authoritative name servers for the domain.

If you do

dig twitter.com NS
Enter fullscreen mode Exit fullscreen mode

This command return something like

dig

These servers are authoritative means they actually contain the actual DNS records ( A , AAAA , CNAME ) for twitter.com

Now if you do

dig twitter.com A
Enter fullscreen mode Exit fullscreen mode

This actually return the IP

DNS

Now the browser finally has the IP address ( 172.66.0.227 )
and it can connect to Twitter and load the website .


Flow

DNS

Image credits : https://www.indusface.com/learning/what-is-dns/

  1. You write
www.twitter.com 
Enter fullscreen mode Exit fullscreen mode
  1. Browser will go to Root nameservers which :
  • Dont gives you IP address

  • It tells you that i know where .com is handled

  1. Then it will go to the TLD nameservers which :
  • Still dont gives you IP address

  • But it return the list of authoritative DNS server for twitter.com

  1. Then it will go to the Authoritative name servers which :
  • Finally return the IP address

  • It contains all the DNS record of the domain

A recursive DNS server finds the IP address on behalf of the client by querying other DNS servers step by step.


Thanks for reading ! if enjoyed this blog , you can read more on this 👇

Top comments (0)