Skip to main content

Command Palette

Search for a command to run...

How DNS Actually Works

Published
4 min read
How DNS Actually Works

A Deep Dive with the dig Command

Ever wondered what happens in those milliseconds between typing "google.com" and the page loading? I did too. Turns out, there's an entire detective story playing out behind the scenes, and today I'm going to walk you through it.

DNS: The Internet's Phonebook (But Way Cooler)

Here's the thing — computers don't understand "google.com". They speak in IP addresses like 142.250.195.46. But nobody wants to memorize a bunch of numbers just to check their email.

Enter DNS (Domain Name System) — a distributed database that translates human-readable domain names into IP addresses. Think of it as the internet's contact list. You ask for "google.com," and DNS returns the actual address where Google lives.

But here's what blew my mind: DNS isn't just one big server somewhere. It's a hierarchical system spread across the globe, and understanding how it works is genuinely fascinating.

Meet Your New Best Friend: The dig Command

Before we dive deeper, let me introduce you to dig (Domain Information Groper). It's a command-line tool that lets you peek behind the curtain of DNS resolution.

dig google.com

That simple command shows you exactly what your computer sees when resolving a domain. It's like having X-ray vision for the internet.

The DNS Hierarchy: Root → TLD → Authoritative

DNS resolution works in layers. Picture it like this:

                    [Root Servers (.)]
                           |
            ┌──────────────┼──────────────┐
            |              |              |
        [.com]          [.org]         [.net]
            |
    ┌───────┼───────┐
    |               |
[google.com]   [amazon.com]

Let's explore each layer using dig.

Layer 1: Root Name Servers

Run this command:

dig . NS

This queries the root name servers — the top of the DNS hierarchy. There are 13 root server clusters (named a.root-servers.net through m.root-servers.net), and they're the starting point for every DNS query.

The output shows NS (Name Server) records pointing to these root servers. They don't know where google.com is, but they know who handles .com domains.

Layer 2: TLD Name Servers

Next up:

dig com NS

This shows the TLD (Top-Level Domain) name servers for .com. These servers are managed by Verisign and handle the entire .com namespace.

You'll see servers like a.gtld-servers.net in the response. These guys don't know Google's exact IP either, but they know which servers are authoritative for google.com.

Layer 3: Authoritative Name Servers

Now we're getting close:

dig google.com NS

This returns Google's authoritative name servers — the servers that actually hold the definitive records for google.com. You'll see something like:

google.com.    NS    ns1.google.com.
google.com.    NS    ns2.google.com.

These are the source of truth for all google.com DNS records.

Putting It All Together: The Full Resolution

Now let's see the complete picture:

dig google.com

Here's what happens behind the scenes:

┌──────────────┐
│  Your Browser │
└──────┬───────┘
       │ "What's google.com?"
       ▼
┌──────────────────┐
│ Recursive Resolver│ (Your ISP or 8.8.8.8)
└──────┬───────────┘
       │
       ▼ Step 1: Ask Root Server
┌──────────────┐
│ Root Server  │ → "Ask .com TLD servers"
└──────────────┘
       │
       ▼ Step 2: Ask TLD Server
┌──────────────┐
│ .com TLD     │ → "Ask ns1.google.com"
└──────────────┘
       │
       ▼ Step 3: Ask Authoritative Server
┌──────────────────────┐
│ ns1.google.com       │ → "142.250.195.46"
└──────────────────────┘
       │
       ▼ Returns IP to browser
┌──────────────┐
│  Your Browser │ → Connects to Google!
└──────────────┘

The recursive resolver (usually your ISP's DNS server or something like Google's 8.8.8.8) does all this legwork for you. It caches results too, so subsequent queries are instant.

What NS Records Actually Mean

NS records are pointers. They say "hey, if you want information about this domain, go ask THESE servers." Each layer of the hierarchy uses NS records to delegate authority downward.

Without NS records, the entire DNS system would collapse. They're the glue holding everything together.

Why This Matters for Web Development

Understanding DNS helps you:

  • Debug deployment issues — "Why isn't my site loading?" might be a DNS propagation problem

  • Configure domains properly — Setting up A records, CNAMEs, and NS records

  • Understand latency — DNS lookup adds time to every request

  • Design distributed systems — Load balancing, failover, and geographic routing all rely on DNS

Next time you type a URL, remember: there's an entire distributed system working to translate those letters into a destination. Pretty cool, right?


This article is part of my learning journey in the Web Dev Cohort 2026. If you found this helpful, feel free to connect!

More from this blog

web-dev-cohort-2026

13 posts