How DNS Works: A Complete Guide for Developers

๐Ÿ“– 8 min read ยท Network Tools ยท Try DNS Lookup Tool โ†’

What is DNS?

DNS stands for Domain Name System. It is the internet's phonebook โ€” a distributed database that translates human-readable domain names like devbench.site into machine-readable IP addresses like 76.76.21.21. Without DNS, you would need to memorize the IP address of every website you visit.

DNS was created in 1983 by Paul Mockapetris to replace a single HOSTS.TXT file that mapped hostnames to IP addresses. As the internet grew, a centralized file became unmanageable. DNS solved this with a hierarchical, distributed system that scales to billions of domains.

How DNS Resolution Works Step by Step

When you type a URL into your browser, a DNS resolution process happens in milliseconds. Here is exactly what occurs:

  1. Browser cache check โ€” Your browser first checks its own DNS cache. If you visited the site recently, the IP address is stored locally and the lookup is instant.
  2. Operating system cache โ€” If not in the browser cache, the OS checks its own DNS cache and the local hosts file (/etc/hosts on Linux/Mac, C:\Windows\System32\drivers\etc\hosts on Windows).
  3. Recursive resolver โ€” If still not found, the query goes to your ISP's recursive DNS resolver (or a public resolver like 8.8.8.8 or 1.1.1.1). This resolver does the heavy lifting on your behalf.
  4. Root nameservers โ€” The resolver queries one of 13 root nameserver clusters. These don't know the IP address but know which nameservers handle each top-level domain (.com, .org, .site, etc.).
  5. TLD nameservers โ€” The root server directs the resolver to the TLD nameserver (e.g., Verisign for .com). The TLD server knows which nameservers are authoritative for the specific domain.
  6. Authoritative nameserver โ€” The resolver queries the domain's authoritative nameserver (usually your hosting provider or Cloudflare). This server has the actual DNS records and returns the IP address.
  7. Response cached and returned โ€” The resolver caches the result for the duration of the TTL (Time to Live) and returns the IP to your browser. Your browser connects to the server at that IP.

This entire process typically takes 20โ€“120 milliseconds on the first visit. Subsequent visits are much faster due to caching.

What is an IP Address?

An IP (Internet Protocol) address is a unique numerical label assigned to every device connected to a network. It serves two purposes: identifying the host and providing the location for routing data packets.

There are two versions of IP addresses in use today:

  • IPv4 โ€” 32-bit addresses written as four numbers separated by dots, e.g., 192.168.1.1. Supports ~4.3 billion unique addresses. Nearly exhausted.
  • IPv6 โ€” 128-bit addresses written as eight groups of hexadecimal digits, e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Supports 340 undecillion addresses โ€” effectively unlimited.

IPv4 vs IPv6: Key Differences

FeatureIPv4IPv6
Address length32 bits128 bits
FormatDecimal (192.168.1.1)Hexadecimal (2001:db8::1)
Total addresses~4.3 billion340 undecillion
NAT requiredYes (address shortage)No
SecurityOptional (IPSec)Built-in (IPSec mandatory)
Header size20 bytes40 bytes (simpler structure)
Adoption~70% of traffic~30% and growing

DNS Record Types Explained

DNS records are instructions stored in authoritative nameservers that tell the DNS system what to do with queries for a domain. Here are the most important record types:

A

Maps a domain to an IPv4 address. The most fundamental DNS record. Example: devbench.site โ†’ 76.76.21.21

AAAA

Maps a domain to an IPv6 address. Same as A record but for IPv6. Example: devbench.site โ†’ 2606:4700::6810:1523

CNAME

Canonical Name โ€” creates an alias from one domain to another. Example: www.devbench.site โ†’ devbench.site. Cannot be used on the root domain.

MX

Mail Exchange โ€” specifies the mail servers responsible for receiving email for the domain. Has a priority value; lower number = higher priority.

TXT

Text records store arbitrary text data. Used for domain verification (Google, GitHub), SPF records (email authentication), DKIM keys, and DMARC policies.

NS

Nameserver records specify which DNS servers are authoritative for the domain. These point to your hosting provider's nameservers.

SOA

Start of Authority โ€” contains administrative information about the zone including the primary nameserver, admin email, and serial number.

PTR

Pointer record โ€” the reverse of an A record. Maps an IP address back to a domain name. Used for reverse DNS lookups and email server verification.

SRV

Service record โ€” specifies the location of servers for specific services. Used by protocols like SIP, XMPP, and Microsoft services.

CAA

Certification Authority Authorization โ€” specifies which certificate authorities are allowed to issue SSL certificates for the domain.

What is TTL (Time to Live)?

TTL is a value in DNS records that tells resolvers how long to cache the record before querying the authoritative nameserver again. It is measured in seconds.

  • Low TTL (300โ€“600 seconds) โ€” Changes propagate quickly (5โ€“10 minutes). Use when you plan to change DNS records soon. Higher load on nameservers.
  • Medium TTL (3600 seconds / 1 hour) โ€” Good balance for most sites. Changes take up to 1 hour to propagate globally.
  • High TTL (86400 seconds / 24 hours) โ€” Fastest resolution for visitors (heavily cached). Changes take up to 24 hours to propagate. Use for stable records.

Pro tip: Before migrating a website, lower your TTL to 300 seconds 24โ€“48 hours in advance. This ensures DNS changes propagate quickly during the migration window.

DNS Troubleshooting Guide

When DNS isn't working correctly, here are the most common issues and how to diagnose them:

Site not loading after DNS change

DNS propagation takes time. Old records are cached by resolvers worldwide. Use our DNS Lookup tool to check what records different nameservers are returning. If the authoritative nameserver shows the new record but your browser doesn't, clear your browser DNS cache (chrome://net-internals/#dns in Chrome) or flush your OS DNS cache.

Email not being received

Check your MX records using the DNS Lookup tool. Verify SPF records (TXT record starting with "v=spf1") are correctly configured. Missing or incorrect MX records are the most common cause of email delivery failures.

SSL certificate errors after DNS change

If you moved to a new host and SSL isn't working, check that your A record points to the new server IP and that the SSL certificate has been issued for the new server. Check CAA records to ensure your certificate authority is allowed.

Slow DNS resolution

Use our Network Speed Test and IP Lookup to check your connection. Consider switching to a faster public DNS resolver: Cloudflare (1.1.1.1), Google (8.8.8.8), or Quad9 (9.9.9.9).

Network Debugging Tools

As a developer, these tools are essential for diagnosing network and DNS issues:

  • nslookup / dig โ€” Command-line tools for querying DNS records. dig devbench.site A returns the A record.
  • ping โ€” Tests connectivity to a host and measures round-trip time. ping devbench.site
  • traceroute / tracert โ€” Shows the path packets take to reach a destination, identifying where delays or failures occur.
  • curl โ€” Tests HTTP responses from the command line. curl -I https://devbench.site shows response headers.
  • whois โ€” Looks up domain registration information including registrar, owner, and expiration date.

Use our free online tools for quick lookups without leaving your browser: