Skip to content

16. DNS

DNS (Domain Name System) is the phonebook of the internet. It translates human-readable domain names (like example.com) into IP addresses (like 192.0.2.1) that computers use to communicate. Without DNS, you would need to remember numeric IP addresses for every website you visit. Understanding DNS helps you comprehend how web requests work and how browsers find websites.

DNS is a hierarchical, distributed naming system that:

  • Maps domain names to IP addresses: Translates names to numbers
  • Distributes responsibility: Multiple servers handle different parts
  • Caches responses: Stores lookups for faster access
  • Provides redundancy: Multiple servers for reliability

When you type a URL in your browser:

  1. Browser checks cache: Looks for recent DNS lookup
  2. OS checks cache: Checks system DNS cache
  3. Resolver query: Queries DNS resolver (usually ISP)
  4. Root server: Queries root DNS servers
  5. TLD server: Queries top-level domain server (.com, .org)
  6. Authoritative server: Queries domain’s nameserver
  7. Response: Returns IP address
  8. Caching: Stores result for future use

Maps domain to IPv4 address:

example.com → 192.0.2.1

Maps domain to IPv6 address:

example.com → 2001:db8::1

Alias for another domain:

www.example.com → example.com

Mail exchange server:

example.com → mail.example.com

Text information (often for verification):

example.com → "v=spf1 include:_spf.google.com ~all"
example.com
│ │
│ └─ Top-Level Domain (TLD)
└─ Second-Level Domain
subdomain.example.com
│ │ │
│ │ └─ TLD
│ └─ Domain
└─ Subdomain
  • 13 root servers: Worldwide distribution
  • Top-level: Handle .com, .org, .net, etc.
  • Distributed: Multiple locations for redundancy

Caching improves performance:

  • Faster lookups: Avoids repeated queries
  • Reduced load: Less traffic on DNS servers
  • Better performance: Faster page loads
  • Browser cache: Short-term storage
  • OS cache: System-level caching
  • Resolver cache: ISP/DNS provider cache
  • TTL: Time-to-live determines cache duration

Changes take time to propagate:

  • TTL settings: Control propagation speed
  • Global distribution: Servers worldwide
  • Caching: Existing caches delay updates

Common causes:

  • Incorrect domain: Typo in domain name
  • Not configured: DNS records not set up
  • Propagation delay: Changes not yet propagated

Setting up domains:

  • A records: Point to server IP
  • CNAME: Alias configurations
  • Subdomains: Create subdomains

CDNs use DNS for routing:

  • Geographic distribution: Route to nearest server
  • Load balancing: Distribute traffic
  • Performance: Faster content delivery
  • Use appropriate TTL: Balance between performance and flexibility
  • Set up redundant DNS: Multiple nameservers
  • Monitor DNS: Track DNS performance
  • Use DNS providers: Reliable DNS services
  • Minimize DNS lookups: Reduce number of domains
  • Use DNS prefetching: Pre-resolve domains
  • Monitor DNS latency: Track resolution times