Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Notes › Computer Networks

DNS — The Internet's Phone Book

Computers connect using IP addresses (76.76.21.21), people remember names (codifylern.vercel.app). The Domain Name System (DNS) translates names into addresses. It is a huge, distributed, hierarchical database.

The hierarchy

                    . (root)                    ← 13 root server names, hundreds of machines (anycast)
          ┌─────────┼──────────┐
        .com      .in        .app               ← TLD (top-level domain) servers
          │         │          │
      google.com  co.in    vercel.app           ← authoritative servers for each domain
                               │
                     codifylern.vercel.app      ← the record you want

A name is read right to left: root → TLD → domain → subdomain.

Resolving www.example.com step by step

  1. Browser cache → OS cache (hosts file too) → router.
  2. Ask the recursive resolver (your ISP, or 8.8.8.8 / 1.1.1.1). If it has the answer cached, done.
  3. Resolver asks a root server → "I don't know, ask the .com TLD servers at …".
  4. Resolver asks the .com TLD server → "ask example.com's nameservers at …".
  5. Resolver asks the authoritative nameserver for example.com → "www.example.com = 93.184.215.14".
  6. Resolver caches it (for the TTL) and returns it to your computer.

Recursive vs iterative queries

Recursive Iterative
"Give me the final answer." The server does all the work. "Give me the best answer you have" — usually a referral to another server.
Your computer → resolver Resolver → root / TLD / authoritative

Record types

Record Maps Example
A name → IPv4 codify.dev A 76.76.21.21
AAAA name → IPv6 codify.dev AAAA 2606:4700::6810:85e5
CNAME name → another name (alias) www CNAME cname.vercel-dns.com
MX mail server for the domain (with priority) codify.dev MX 10 mail.provider.com
TXT free text — domain verification, SPF, DKIM, DMARC "google-site-verification=…"
NS which nameservers are authoritative ns1.provider.com
SOA zone info (primary NS, serial, timers) —
PTR IP → name (reverse DNS) used by mail servers
SRV service location (host + port) VoIP, games
CAA which CAs may issue certificates 0 issue "letsencrypt.org"

Rule: a CNAME can't sit at the root of a domain (example.com) next to other records — providers offer ALIAS/ANAME/"CNAME flattening" for that.

TTL and caching

Every record has a TTL (time to live) in seconds. Resolvers and browsers cache answers until it expires.

Setting up a custom domain (practical)

  1. Buy the domain from a registrar.
  2. Point an A record for the apex (codify.dev) to the host's IP, and a CNAME for www to the host's name (e.g. Vercel/Netlify tell you the exact values).
  3. For email: add MX records plus SPF/DKIM/DMARC TXT records so mail isn't marked as spam.
  4. Verify with: nslookup codify.dev, dig codify.dev A +short, dig codify.dev MX.

DNS and load distribution

Security

Threat What happens Defence
DNS spoofing / cache poisoning fake answers stored in a resolver, users sent to a bad IP DNSSEC (signed records), random source ports/IDs
Eavesdropping ISP sees every name you look up DoH (DNS over HTTPS), DoT (DNS over TLS)
DDoS on DNS providers sites become unreachable anycast, multiple providers
Domain hijacking attacker changes your NS records registrar lock, 2FA

Interview one-liners

More Computer Networks notes