Skip to main content

Command Palette

Search for a command to run...

How DNS find Websites ?

Published
•4 min read•View as Markdown
B
I am a third-year undergrad student at Chandigarh University. I am into building backend and applied AI stuff using the modern technologies. I loves to document my learning through the blogs so that I can contribute to the community.

What is DNS ?

First let go through standard google definition which says “DNS (Domain Name System) is the internet's phonebook”. Apart from this it also translates the the the human-readable URL into machine-readable IP addresses. So by this definition what do you think what actually happens when we write google.com in the browser? The request enters the DNS Resolver and there it finds the the IP addresses of google.com and then it returns the IP to the browser. It is not that simple to understand. Lets see what actually happens under the hoods(magic of DNS).

Root Server

The first request hits the Root Server which tells the servers that are responsible for each TLD - Top Level Domain (.com, .org, .in, etc.)
So we have total of 13 Root servers exists in the whole world. It is not like the actual severs rather there are many many servers which replicates 13 servers and are deployed to different corners of the world. So on asking this this the root server responds that “I know the name servers(NS) for .com and everything else you should go and ask to TLD Servers. So here we are redirected to TLD Servers.

TLD Servers

Again the request hits this server asking do you know where is the IP of google.com. And here we gets same response but with some more information. It tells I can give you the name of the authoritative server for the domain google.com. But still I cannot tell what is the IP of the google.com.

Authoritative Servers

Now here comes the final call to authoritative servers like Vercel, Hostinger, GoDaddy, etc. the platform you buys your domain and assigns you server’s IP to it. Here the several records like A, AAAA, MX, etc. are configured. Among this the A/AAAA stores the address of the domain for which the the whole drama was created.

Recursive DNS Servers

So as we see getting a IP addresses from a domain name(URL) is very difficult, so all this stuff are not executed by the browser itself rather a another called Recursive DNS Server which sits at the front of the whole DNS ball game actually handles it and the browsers just talks to this layer. Another thing is that to minimize the DNS resolving time many caching techniques are used at different levels of DNS system making the whole system superfast despite of so many requests.

And yes this is the end of DNS Recursive Resolver that started with root servers to find TLD servers to find authoritative server.

Some Awesome Dig Commands

What is Dig ?

Dig stands for Domain Information Groper which is tool that is used to overserve and debug the DNS resolution. It is widely used to go inside the IP resolutions and solve the DNS issues.

Commands

  1. dig: This is the simplest command written as dig google.com. So it return us four things:

     ;; ANSWER SECTION:
     google.com.   77 IN   A   172.217.24.78
    
    1. google.com → the domain

    2. 77→ TTL (seconds DNS can cache this result)

    3. A → record type (IPv4 address)

    4. 172.217.24.78 → IP address of the server

  2. dig . NS: This command gives all the responsible name servers(NS) for the root DNS zone. We have 13 root DNS servers which can be seem as follows

     ;; ANSWER SECTION:
     .                       87203   IN      NS      f.root-servers.net.
     .                       87203   IN      NS      b.root-servers.net.
     .                       87203   IN      NS      h.root-servers.net.
     .                       87203   IN      NS      d.root-servers.net.
     .                       87203   IN      NS      k.root-servers.net.
     .                       87203   IN      NS      i.root-servers.net.
     .                       87203   IN      NS      l.root-servers.net.
     .                       87203   IN      NS      e.root-servers.net.
     .                       87203   IN      NS      c.root-servers.net.
     .                       87203   IN      NS      g.root-servers.net.
     .                       87203   IN      NS      j.root-servers.net.
     .                       87203   IN      NS      a.root-servers.net.
     .                       87203   IN      NS      m.root-servers.net.
    
  3. dig com NS: As com lies in the TLD layer so this command will give all the name servers(NS) responsible for “com” TLD which looks something this:

     ;; ANSWER SECTION:
     com.                    21600   IN      NS      e.gtld-servers.net.
     com.                    21600   IN      NS      h.gtld-servers.net.
     com.                    21600   IN      NS      m.gtld-servers.net.
     com.                    21600   IN      NS      c.gtld-servers.net.
     com.                    21600   IN      NS      g.gtld-servers.net.
     com.                    21600   IN      NS      f.gtld-servers.net.
     com.                    21600   IN      NS      j.gtld-servers.net.
     com.                    21600   IN      NS      l.gtld-servers.net.
     com.                    21600   IN      NS      b.gtld-servers.net.
     com.                    21600   IN      NS      k.gtld-servers.net.
     com.                    21600   IN      NS      i.gtld-servers.net.
     com.                    21600   IN      NS      a.gtld-servers.net.
     com.                    21600   IN      NS      d.gtld-servers.net.
    
  4. dig google.com NS: This command lists all the name servers for the domain google.com which looks something like this:

     ;; ANSWER SECTION:
     google.com.             17634   IN      NS      ns1.google.com.
     google.com.             17634   IN      NS      ns3.google.com.
     google.com.             17634   IN      NS      ns2.google.com.
     google.com.             17634   IN      NS      ns4.google.com.
    

    All the name on rightmost section are the named servers of google.com and if we notice the name server has google written in it, this means this server are owned by google themselves.

So in this way we can use the dig command in order to find the DNS servers and their names and IP addresses.