DEV Community

Cover image for How does DNS Resolution Works
Souvik Guha Roy
Souvik Guha Roy

Posted on

How does DNS Resolution Works

In this blog, we will cover:

  • What DNS is and why name resolution exists
  • What the dig command is 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 complete DNS resolution flow

What is DNS (Domain Name System)?

DNS stands for Domain Name System.
Its main job is to convert human-friendly domain names like:

www.example.com
Enter fullscreen mode Exit fullscreen mode

into computer-friendly IP addresses like:

192.168.1.1
Enter fullscreen mode Exit fullscreen mode

Think of DNS as the phonebook of the internet. Humans remember names, but computers communicate using numbers. DNS bridges that gap.


Why Does Name Resolution Exist?

  • Humans can easily remember names like twitter.com
  • Computers understand numbers like 192.8.1.1

So, DNS acts as a translator between humans and machines, allowing us to access websites using names instead of memorizing IP addresses.


What is the dig Command?

dig stands for Domain Information Groper.

It is a command-line tool used to retrieve information from DNS servers. Network administrators and engineers commonly use dig to:

  • Perform DNS lookups
  • Verify DNS configurations
  • Troubleshoot DNS issues

When is dig Used?

  • Debugging DNS resolution problems
  • Checking which DNS servers are authoritative for a domain
  • Verifying DNS records like A, AAAA, CNAME, MX, etc.

Basic Syntax

dig [server] [domain] [record_type]
Enter fullscreen mode Exit fullscreen mode

Example:

dig twitter.com A
Enter fullscreen mode Exit fullscreen mode

How DNS Resolution Works (Step by Step)

Let’s understand what actually happens when you type:

www.twitter.com
Enter fullscreen mode Exit fullscreen mode

into your browser.


1. Root Name Servers

Root name servers are the starting point of the DNS hierarchy.

  • There are 13 logical root servers (named A to M)
  • Each logical server has many physical instances worldwide
  • Root servers do not know the IP address of websites

Instead, they guide the resolver by saying:

“I don’t know the IP, but I know where .com domains are handled.”

Check Root Name Servers

dig . NS
Enter fullscreen mode Exit fullscreen mode

This command returns the list of root name servers.


2. TLD (Top-Level Domain) Name Servers

TLD stands for Top-Level Domain, such as:

  • .com
  • .net
  • .org
  • .in

TLD servers also do not return IP addresses.
Their job is to point to the authoritative name servers for a domain.

Check TLD Name Servers for .com

dig com NS
Enter fullscreen mode Exit fullscreen mode

This returns the authoritative name servers responsible for all .com domains.

At this point, the resolver knows exactly where to go next.


3. Authoritative Name Servers

Authoritative name servers are where the actual DNS records live.

When you run:

dig twitter.com NS
Enter fullscreen mode Exit fullscreen mode

You get a list of name servers that are authoritative for twitter.com.

These servers contain real DNS records such as:

  • A (IPv4 address)
  • AAAA (IPv6 address)
  • CNAME
  • MX

Getting the Actual IP Address

dig twitter.com A
Enter fullscreen mode Exit fullscreen mode

This finally returns the IP address, for example:

172.66.0.227
Enter fullscreen mode Exit fullscreen mode

Now the browser knows where to connect and can load the Twitter website.


Complete DNS Resolution Flow (Summary)

  1. You type www.twitter.com in your browser
  2. The browser asks a recursive DNS resolver
  3. The resolver queries Root Name Servers
  • Root servers say: “Ask .com TLD servers”

    1. The resolver queries TLD Name Servers
  • TLD servers say: “Here are the authoritative servers for twitter.com”

    1. The resolver queries Authoritative Name Servers
  • These servers return the actual IP address

    1. The browser connects to the IP and loads the website

Final Notes

  • Root servers → know where TLDs are
  • TLD servers → know which servers are authoritative
  • Authoritative servers → know the actual IP address
  • Recursive DNS servers perform this entire lookup on behalf of the client

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

Top comments (0)