Networking basics, How DNS Works

The Domain Name System (DNS) is the internet’s phonebook. It translates human-readable domain names like example.com into IP addresses that computers use to communicate. This tutorial explains how DNS works and why it's essential to internet functionality.

Step 1: What is DNS?

DNS maps domain names to IP addresses so users can access websites using friendly URLs instead of numeric IPs.

Step 2: The DNS Resolution Process

When you type a URL into your browser, DNS resolution happens in several steps:

  1. Browser cache: Checks if the domain is cached locally.
  2. Operating system: If not found, checks the system resolver cache.
  3. Router: May have DNS caching or forward the request.
  4. Recursive DNS server: Performs the lookup on behalf of the user.
  5. Root server: Directs to the correct Top-Level Domain (TLD) server (.com, .org, etc.).
  6. TLD server: Points to the authoritative DNS server for the domain.
  7. Authoritative server: Returns the final IP address.

This all happens in milliseconds!

Step 3: Types of DNS Records

  • A: Maps a domain to an IPv4 address.
  • AAAA: Maps a domain to an IPv6 address.
  • CNAME: Canonical name for aliasing.
  • MX: Mail exchange record (email routing).
  • NS: Name server record.
  • TXT: Used for SPF, domain verification, etc.

Step 4: TTL (Time to Live)

TTL defines how long a DNS record is cached before a new query is needed. Lower TTLs mean more up-to-date records, higher TTLs reduce DNS traffic.

Step 5: DNS Security (DNSSEC)

DNSSEC adds cryptographic signatures to DNS records to prevent spoofing and man-in-the-middle attacks. It ensures the integrity of the DNS response.

Step 6: Tools to Inspect DNS

  • nslookup – basic DNS queries
  • dig – advanced DNS diagnostics
  • host – simple hostname lookup

Next Steps

Try running dig google.com in your terminal to see the resolution process. Understanding DNS is crucial for web development, network administration, and debugging connectivity issues.