AboutBlogRSS

DNS 101

A Practical Guide of key information needed to know about DNS to host web apps

Ever deployed a web app only to find yourself staring at a blank screen instead of your beautiful creation? You're not alone. I recently spent many frustrating hours debugging why a newly deployed application wasn't working, only to discover it was a simple DNS configuration issue. DNS problems are the silent killers - they seem simple until they're not, and suddenly you're down a rabbit hole of technical jargon.

The worst part? Most DNS tutorials either oversimplify ("just point your domain to this IP!") or overwhelm you with network engineering concepts you don't need. There's rarely a middle ground that gives developers exactly what they need to know - no more, no less.

When You'll Need This Knowledge

You'll run into DNS challenges when:

  • Launching a new website
  • Switching hosting providers
  • Setting up custom email
  • Adding SSL certificates
  • Creating subdomains for different services

The good news? You don't need to become a network engineer. Just a few practical concepts will solve most issues you'll face.

What This Post Will Deliver

By the end of this post, you'll have a practical understanding of DNS that actually matters for web development. I'll give you the mental model and debugging tools to solve 90% of the DNS issues you'll encounter when deploying web applications.

We will define what each (poorly named) entity does and why so you can reason about issues,

You'll learn how to methodically trace DNS issues through the entire resolution chain, with Python code snippets you can run to diagnose problems at each step. Here's a quick example of checking if your domain is properly registered:

import whois

domain = "isaacflath.com"
w = whois.whois(domain)
print(f"Registrar: {w.registrar}")
print(f"Creation Date: {w.creation_date}")
print(f"Expiration Date: {w.expiration_date}")
Registrar: NAMECHEAP INC
Creation Date: 2025-03-13 05:06:07
Expiration Date: 2027-03-13 05:06:07

Context Setting: Background and Foundation

DNS (Domain Name System) is essentially the internet's phone book - it translates human-friendly domain names like "isaacflath.com" into machine-friendly IP addresses like "192.168.1.1" that computers use to find each other.

This translation happens through a hierarchical system of servers, each responsible for different parts of the domain name resolution process. Understanding this hierarchy is key to diagnosing issues when things go wrong.

This diagram illustrates this hierarchy, from root servers at the top to your specific DNS records at the bottom. Each component plays a crucial role, and problems can occur at any level - which is why having a systematic debugging approach is so valuable. We will walk through each step in this blog post.

🙏 I have a huge amount of gratitude to Alexis Gallagher who has taught me a great deal about DNS. I would not have the knowledge required to write this post if not for him.

As you read the blog post, keep referring back to this diagram and understand where you are in it. This diagram is what you really need to know!

flowchart TD %% Define nodes with consistent background color Registrar["Domain Registrar
(e.g. Namecheap)
whois domain.com"] Registry["Domain Registry
(e.g. Verisign for .com)
whois domain.com"] NameServers["Name Servers
(NS records)
dig NS domain.com"] RootServers["Root Servers
(13 worldwide)
dig NS ."] TLDServers["TLD Servers
(.com, .org etc)
dig NS com."] ISPServers["ISP/Recursive DNS Servers
dig domain.com"] UserDevice["User's Device
DNS Request
nslookup domain.com"] WebServer["Web Server
(A/CNAME records)
dig A domain.com
dig CNAME example.com
"] %% Define connections with labels Registrar -->|"Register domain name"| Registry Registry -->|"Update root servers"| RootServers Registrar -->|"Configure DNS records"| NameServers RootServers -->|"Delegate to TLD servers"| TLDServers TLDServers -->|"Delegate to authoritative NS"| UserDevice NameServers -->|"Provide DNS records"| ISPServers UserDevice -->|"Query propagates"| ISPServers ISPServers -->|"Cache and return results"| WebServer %% Style all nodes with the same background color classDef defaultStyle fill:#f0f8ff,stroke:#333,stroke-width:2px %% Apply consistent style to all nodes class Registrar,Registry,NameServers,RootServers,TLDServers,ISPServers,UserDevice,WebServer defaultStyle %% Add direction linkStyle default stroke:#666,stroke-width:2px,color:black;

DNS Diagnositcs

Domain Registrar & Registry

Domain Registrar = The Store Where You Buy Your Listing

  • This is like a shop (e.g., Namecheap, GoDaddy) where you go to "buy" your domain name
  • You pay them a fee to reserve your unique name (e.g., isaacflath.com) for a period of time
  • They handle the paperwork and customer service
  • Important: Registrars allow you to configure nameservers for your domain, which determine where your DNS records are stored and managed

Domain Registry = The Official Record Keeper

  • This is the organization (e.g., Verisign for .com domains) that maintains the master database
  • They're like the government office that maintains property records
  • They don't deal with individual customers, but work with registrars

ICANN = The Governing Authority

  • The Internet Corporation for Assigned Names and Numbers oversees the entire domain name system
  • They accredit registrars and establish policies for domain registration
  • They ensure the stability and security of the domain name system globally

Analogy

Imagine buying a plot of land. The domain registrar is like the real estate agent who handles your purchase, while the domain registry is like the county records office that maintains the official database of who owns what property. You deal with the agent (registrar), who then ensures your ownership is recorded with the official record keeper (registry). ICANN would be like the government agency that regulates real estate transactions and maintains standards.

When you register a domain, your registrar collects your information and payment, then notifies the appropriate registry to record that you now "own" that domain name for the duration of your registration period.

Checking Domain Registration

You can check domain registration information using the whois command

%%bash
whois isaacflath.com | grep Registrar:
   Registrar: NameCheap, Inc.
Registrar: NAMECHEAP INC

This will return detailed information about the domain, including registrar, registration dates, and nameserver information. I have filtered it with grep to only show the Registrar, but try running it yourself to see all the information it provides!

Here's some key information to look at (you will understand more of what the results mean by the end of the blog post :))

%%bash
whois isaacflath.com | grep -E 'Registrar:|Name Server:|Creation Date:|Expiration Date:' | grep -v 'Registrar URL'
   Creation Date: 2025-03-13T05:06:07Z
   Registrar: NameCheap, Inc.
   Name Server: PDNS1.REGISTRAR-SERVERS.COM
   Name Server: PDNS2.REGISTRAR-SERVERS.COM
Creation Date: 2025-03-13T05:06:07.00Z
Registrar Registration Expiration Date: 2027-03-13T05:06:07.00Z
Registrar: NAMECHEAP INC
Name Server: pdns1.registrar-servers.com
Name Server: pdns2.registrar-servers.com

Root Servers

Root Servers = The Top of the DNS Hierarchy

  • These are 13 special server clusters (labeled A through M) distributed worldwide
  • They're the first step in the DNS resolution process
  • They maintain information about the authoritative nameservers for top-level domains (TLDs)
  • Important: Root servers don't store information about specific domains, but direct queries to the appropriate TLD servers

TLD Servers = The Next Level Down

  • These servers maintain information about domains under specific TLDs (.com, .org, .net, etc.)
  • They know which nameservers are authoritative for each domain within their TLD
  • When queried, they respond with the nameservers responsible for the specific domain

IANA = The Root Zone Manager

  • The Internet Assigned Numbers Authority manages the DNS root zone
  • They coordinate the global pool of IP addresses and AS numbers

Analogy

Imagine walking into a huge library looking for a specific book. You first go to the main directory at the entrance. This directory doesn't tell you exactly where your book is, but it directs you to the right floor or section (like "Fiction, 3rd floor" or "Science, west wing"). Root servers work the same way - they don't know where "isaacflath.com" is, but they know to direct you to the servers that handle all ".com" domains.

When your computer looks up a website, it often starts by asking a root server "Where can I find information about .com domains?" The root server responds with directions to the TLD servers that handle .com domains.

Checking Root Servers

You can check root servers using the dig command:

%%bash
dig NS . +short
m.root-servers.net.
k.root-servers.net.
a.root-servers.net.
c.root-servers.net.
j.root-servers.net.
b.root-servers.net.
h.root-servers.net.
l.root-servers.net.
i.root-servers.net.
e.root-servers.net.
f.root-servers.net.
g.root-servers.net.
d.root-servers.net.

This will return a list of the root nameservers that form the foundation of the global DNS system.

TLD Servers

TLD Servers = The Section Managers of the Internet

  • These servers are responsible for specific top-level domains (.com, .org, .net, etc.)
  • They maintain information about all domains registered under their TLD
  • They direct queries to the appropriate authoritative nameservers for specific domains
  • Important: TLD servers don't store the actual DNS records for your domain, but know which nameservers do

Registry Operators = The TLD Administrators

  • Organizations like Verisign (for .com and .net) manage TLD servers
  • They maintain the authoritative database for their TLDs
  • They work with registrars to update domain information
  • Different TLDs may have different registry operators (e.g., Public Interest Registry for .org)

Analogy

If root servers are like the main directory of a library that points you to different sections, TLD servers are like the section-specific information desks. When you arrive at the "Fiction Section" (the .com TLD), the information desk there doesn't know exactly where every book is, but it can tell you which shelf contains the specific author you're looking for. Similarly, the .com TLD servers don't know the IP address for isaacflath.com, but they know which nameservers are responsible for that domain.

Checking TLD Servers

You can check TLD servers using the dig command:

%%bash
dig NS com. +short
d.gtld-servers.net.
b.gtld-servers.net.
g.gtld-servers.net.
h.gtld-servers.net.
k.gtld-servers.net.
c.gtld-servers.net.
m.gtld-servers.net.
j.gtld-servers.net.
e.gtld-servers.net.
a.gtld-servers.net.
l.gtld-servers.net.
f.gtld-servers.net.
i.gtld-servers.net.

This will return a list of the nameservers responsible for the .com top-level domain, which are crucial in the DNS resolution chain for all .com websites.

Authoritative Nameservers

Authoritative Nameservers = The Final Authority for Your Domain

  • These servers hold the actual DNS records for your specific domain
  • They provide definitive answers about your domain's IP addresses and other configurations
  • They're typically provided by your DNS host (could be your registrar, hosting provider, or a third-party DNS service)
  • Important: These are configured at your registrar and determine where all your DNS records are stored and managed

DNS Zone = Your Domain's Complete Record Collection

  • A DNS zone is the complete set of records for your domain
  • It contains all the information about how to route traffic to your domain
  • It's maintained on your authoritative nameservers
  • Changes to your DNS records are made in this zone

Analogy

If the DNS system is like a library, authoritative nameservers are the specific bookshelves where your book is stored. When someone asks, "Where can I find the book 'isaacflath.com'?", they're first directed to the main entrance (root servers), then to the correct section (TLD servers), and finally to the exact shelf (authoritative nameservers) where your book is located. The authoritative nameservers then provide the exact location (IP address) where the content can be found.

Checking Authoritative Nameservers

You can check authoritative nameservers and query them directly using dig:

%%bash
# Find nameservers
dig NS isaacflath.com +short
pdns2.registrar-servers.com.
pdns1.registrar-servers.com.

Check A records from one of these nameservers

%%bash
# Query a specific nameserver for A records
dig @pdns1.registrar-servers.com isaacflath.com A +short
7el1rp37.up.railway.app.

A and CNAME Records: Directing Traffic to Your Web Server

A Records = The Direct IP Address Pointer

  • These records map your domain name directly to a specific IPv4 address (e.g., 192.168.1.1)
  • They're the crucial final step in the DNS resolution chain
  • When someone types your domain in their browser, A records provide the actual server location (like where you app is running)

CNAME Records = Aliases for Your Domain

  • These create an alias pointing one domain to another (e.g., www.example.com → example.com)
  • They don't contain IP addresses directly but point to another domain name that will be resolved
  • They're useful for subdomains that should point to the same destination as your main domain

CNAME Limitations and Considerations

  • The target of a CNAME must be a domain name, not an IP address
  • CNAME records cannot exist on the apex/root domain (example.com) in standard DNS
  • A domain with a CNAME record cannot have other record types (like MX or TXT)
  • They're ideal for third-party services integration (blog.yourdomain.com → hosting-service.com)

TTL (Time To Live) = Cache Duration

  • This value determines how long DNS resolvers should cache your records
  • Lower TTL values mean changes propagate faster but increase DNS lookup traffic
  • Higher TTL values improve performance but slow down propagation of changes

Other DNS Records = The Specific Instructions for Your Domain

  • AAAA Records: Map a domain to an IPv6 address
  • MX Records: Direct email to the correct mail servers
  • TXT Records: Store text information (often used for verification and security)

Analogy

If the DNS system is like a delivery service, A records are the exact coordinates where your package (web request) should be delivered. After going through all previous DNS servers, the browser finally gets the exact address (IP address) where your website is hosted.

CNAME records are like mail forwarding. When a request arrives for "www.example.com," the DNS system checks its records and sees instructions to "forward all requests to example.com instead." The browser then follows that domain's address resolution path.

Checking A and CNAME Records

You can check these records using the dig command:

%%bash
dig A isaacflath.com +short
7el1rp37.up.railway.app.
trestle.proxy.rlwy.net.
35.212.94.98
%%bash
dig CNAME www.isaacflath.com +short
isaacflath.com.

These commands will show you the IP addresses associated with your domain and any domain aliases, which are essential for directing web traffic to the correct destination.

ISP/Recursive DNS Servers

ISP/Recursive DNS Servers = Your Personal DNS Navigator

  • These servers handle DNS resolution requests from your devices
  • They query the DNS hierarchy on your behalf, starting from root servers if necessary
  • They're typically provided by your Internet Service Provider or public services (like Google's 8.8.8.8 or Cloudflare's 1.1.1.1)
  • Important: These servers cache results to improve performance, which affects how quickly DNS changes propagate

DNS Resolution Process = The Complete Journey

  • When you type a domain name, your device first checks its local cache
  • If not found, it queries the recursive DNS server configured in your network settings
  • The recursive server either returns a cached result or performs a full lookup through the DNS hierarchy
  • Results are cached according to the TTL (Time To Live) values specified in the DNS records

DNS Caching = Performance vs. Propagation

  • Caching reduces load on authoritative servers and speeds up common lookups
  • Different recursive servers may have different cached values during DNS changes
  • This is why some users might see your new website while others still see the old one
  • Important: You cannot force cache expiration on recursive servers you don't control

Analogy

If the DNS system is like a library, recursive DNS servers are like research assistants who know the library's organization. When you need information, instead of navigating the complex library system yourself, you simply ask your assistant "Where can I find isaacflath.com?" The assistant either immediately tells you from memory (cache) or goes through the process of consulting the main directory (root servers), finding the right section (TLD servers), and locating the specific shelf (authoritative nameservers) to get your answer.

Checking Recursive DNS Resolution

You can check how different recursive DNS servers resolve your domain:

For example, Google DNS resolution:

%%bash
dig @8.8.8.8 isaacflath.com +short
7el1rp37.up.railway.app.
trestle.proxy.rlwy.net.
35.212.94.98

Or Cloudflare DNS resolution:

%%bash
dig @1.1.1.1 isaacflath.com +short
7el1rp37.up.railway.app.
trestle.proxy.rlwy.net.
35.212.94.98

This will show you how major public DNS providers are currently resolving your domain, which is useful for checking if DNS changes have propagated globally.

Local Cache

Local DNS Cache = Your Device's Memory of Previous Lookups

  • This is the DNS information stored directly on your computer, phone, or other device
  • Your operating system maintains this cache to avoid repeated DNS lookups
  • It's the first place your device checks before making external DNS queries
  • Important: Outdated cache entries can cause confusion when DNS records change

Browser DNS Cache = Browser-Specific DNS Storage

  • Most web browsers maintain their own separate DNS cache
  • This adds another layer of caching beyond your operating system
  • Different browsers on the same device might show different results during DNS changes
  • Browser caches typically have shorter retention times than OS-level caches

Analogy

Think of your local DNS cache like a personal address book. When you need to visit a friend, you first check your address book to see if you already know where they live. Only if you don't have their address (or suspect it might have changed) do you ask someone else. Similarly, your device first checks its local cache before asking recursive DNS servers for domain information.

Checking Your Local DNS Resolution

You can check how your local system is currently resolving a domain using Python:

import socket

domain = "isaacflath.com"
try:
    ip = socket.gethostbyname(domain)
    print(f"Local resolution: {domain} -> {ip}")
except socket.gaierror as e:
    print(f"Resolution error: {e}")
Local resolution: isaacflath.com -> 35.212.94.98

Viewing and Clearing Your Local DNS Cache

For Windows:

%%bash
# View DNS cache
ipconfig /displaydns

# Clear DNS cache
ipconfig /flushdns

For macOS:

%%bash
# Clear DNS cache (macOS 10.15+)
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

For Linux:

%%bash
# Restart the nscd service if installed
sudo systemctl restart nscd

This allows you to clear your local DNS cache when troubleshooting, which is often the first step in resolving DNS-related issues after making changes to your domain configuration.

import requests

domain = "isaacflath.com"
try:
    response = requests.get(f"https://{domain}", timeout=5)
    print(f"Status code: {response.status_code}")
    print(f"Server responded in {response.elapsed.total_seconds():.2f} seconds")
    print(f"Server type: {response.headers.get('Server', 'Unknown')}")
except requests.exceptions.RequestException as e:
    print(f"Connection error: {e}")
Status code: 200
Server responded in 0.52 seconds
Server type: railway-edge

You can also check if specific ports are open:

Troubleshooting DNS Issues: A Complete Solution

When facing DNS problems, follow this systematic approach to identify and resolve issues at each level of the DNS hierarchy:

1. Check Domain Registration

import whois
domain = "yourdomain.com"
w = whois.whois(domain)
print(f"Registrar: {w.registrar}")
print(f"Creation Date: {w.creation_date}")
print(f"Expiration Date: {w.expiration_date}")

✅ Verify your domain is properly registered and not expired

2. Verify Nameserver Configuration

dig NS yourdomain.com +short

✅ Confirm nameservers match what's configured at your registrar

3. Check DNS Records

# A Records
dig A yourdomain.com +short

# CNAME Records
dig CNAME www.yourdomain.com +short

✅ Ensure records point to the correct IP addresses or domains

4. Test DNS Propagation

# Check with different public DNS providers
dig @8.8.8.8 yourdomain.com +short  # Google DNS
dig @1.1.1.1 yourdomain.com +short  # Cloudflare DNS

✅ If results differ, you may need to wait for propagation

5. Verify Web Server Connectivity

import requests
import socket

# Check HTTP response
try:
    response = requests.get(f"https://yourdomain.com", timeout=5)
    print(f"Status code: {response.status_code}")
except requests.exceptions.RequestException as e:
    print(f"Connection error: {e}")
    
# Check if ports are open
def check_port(domain, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(2)
    result = sock.connect_ex((domain, port))
    sock.close()
    return result == 0

print(f"HTTP (port 80) open: {check_port('yourdomain.com', 80)}")
print(f"HTTPS (port 443) open: {check_port('yourdomain.com', 443)}")

✅ Confirm your web server is responding properly

Common Solutions

  1. Domain not resolving: Update nameservers at your registrar
  2. Subdomain issues: Add appropriate CNAME or A records
  3. Slow propagation: Lower TTL values (300-3600 seconds)
  4. Inconsistent results: Clear local DNS cache with:
    # Windows
    ipconfig /flushdns
    
    # macOS
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    
    # Linux
    sudo systemctl restart nscd
    

Remember that changes can take time to propagate globally (up to 24-48 hours), though most updates are visible within minutes to hours with modern configurations.

Conclusion: Mastering DNS for Web Developers

DNS might seem like a complex system, but with the mental model and debugging tools we've covered, you now have everything you need to confidently manage your domain configurations and troubleshoot issues when they arise.

Key Takeaways

  • DNS is hierarchical: From root servers to your specific records, understanding this hierarchy helps you pinpoint where problems occur
  • Systematic debugging works: Follow the complete solution workflow to methodically trace issues through the entire DNS chain
  • Patience is sometimes required: Remember that DNS propagation takes time, especially with higher TTL values
  • Tools matter: Simple commands like dig, whois, and basic Python scripts can save you hours of frustration

Next Steps

Now that you understand DNS fundamentals, try mapping out how your favorite blog's DNS works!

Have you encountered particularly tricky DNS issues? Share your experiences in the comments - I'd love to hear how you solved them and what you learned in the process.

And if this guide helped you solve a DNS problem, let me know! There's nothing more satisfying than knowing these practical guides are making someone's development life a little easier.

Happy deploying!

Stay Updated

Get notified about new posts on AI, web development, and tech insights.

Let's Connect

© 2025 Isaac Flath • All rights reserved