Skip to content
beginnerPhase 29 · Web Foundations

DNS

Learn how domain names are resolved to IP addresses through DNS hierarchy.

30m
0 problems
Topic Progress0%

What is DNS

DNS (Domain Name System) is the phonebook of the internet. It translates human-readable domain names (google.com) into IP addresses (142.250.80.46).

Why DNS Exists

Humans remember names; computers remember numbers. DNS bridges this gap.

Without DNS:
You'd type: http://142.250.80.46/search?q=cats

With DNS:
You type: https://www.google.com/search?q=cats

DNS Hierarchy

. (Root)
├── .com (TLD - Top Level Domain)
│   ├── google.com (Second Level Domain)
│   │   ├── www.google.com (Subdomain)
│   │   ├── mail.google.com
│   │   └── docs.google.com
│   └── amazon.com
├── .org
├── .net
├── .uk (Country Code TLD)
└── .io

DNS Components

Component Role Example
Resolver Client-side DNS query handler Your ISP's DNS server
Root Nameserver First stop in resolution a.root-servers.net
TLD Nameserver Manages top-level domains .com nameservers
Authoritative NS Final authority for domain ns1.google.com

DNS Record Analogy

Think of DNS like a phone book:

  • A Record: Name → Phone number (IP address)
  • MX Record: Name → Fax number (mail server)
  • CNAME: Nickname → Real name (alias)
  • TXT Record: Notes about the contact (SPF, DKIM)

DNS Resolution Process

When you type a URL, DNS resolves the domain to an IP through multiple steps.

Full Resolution Flow

1. Browser Cache
   Check if domain was recently resolved
   ↓ (cache miss)

2. OS Cache
   Check operating system DNS cache
   ↓ (cache miss)

3. Router Cache
   Check local network router cache
   ↓ (cache miss)

4. ISP DNS Resolver
   Recursive resolver provided by ISP
   ↓ (cache miss)

5. Root Nameserver
   Query root server (.)
   Returns: .com TLD server address
   ↓

6. TLD Nameserver
   Query .com nameserver
   Returns: authoritative nameserver for domain
   ↓

7. Authoritative Nameserver
   Query domain's authoritative server
   Returns: IP address for the domain
   ↓

8. Response
   IP address returned to browser
   Cached for TTL duration

Iterative vs Recursive Queries

Recursive (Client → Resolver):

  • Client asks resolver to do all the work
  • Resolver returns final answer

Iterative (Resolver → Nameservers):

  • Resolver queries each server in chain
  • Each server returns next server to query
  • Resolver follows the chain

DNS Caching

Layer Typical TTL
Browser 60-300 seconds
OS 300-3600 seconds
Router 300-3600 seconds
ISP Resolver Varies by record
Authoritative Set by domain owner

DNS Propagation

When DNS records change, updates spread across the internet:

  • Can take minutes to 48 hours
  • Depends on TTL values
  • Different resolvers may see different results during propagation

DNS Record Types

DNS records map domain names to various types of data.

Core Record Types

Record Purpose Example
A Domain → IPv4 address example.com → 93.184.216.34
AAAA Domain → IPv6 address example.com → 2606:2800:220:1::24e
CNAME Domain alias to another domain www.example.com → example.com
MX Mail server for domain example.com → mail.example.com
NS Nameserver for domain example.com → ns1.example.com
TXT Text information SPF, DKIM, verification records
SOA Start of Authority, zone metadata Zone admin info

Common Use Cases

A Record (Most Common):

example.com.   300   IN   A   93.184.216.34

CNAME (Subdomain Alias):

www.example.com.   3600   IN   CNAME   example.com.

MX (Email):

example.com.   3600   IN   MX   10   mail.example.com.
example.com.   3600   IN   MX   20   backup.example.com.

TXT (Email Authentication):

example.com.   3600   IN   TXT   "v=spf1 mx ~all"

AAAA (IPv6):

example.com.   300   IN   AAAA   2606:2800:220:1:24e:2800:349:e36

Special Record Types

Type Purpose
SRV Service location (VoIP, XMPP)
PTR Reverse DNS (IP → domain)
CAA Certificate Authority Authorization
DNSKEY DNSSEC public key
DS DNSSEC delegation signer

DNS Record Format

name  TTL  class  type  value

example.com.  3600  IN  A  93.184.216.34
|___________| |__| |__| |__| |_________|
   name      TTL  class type   value
  • IN: Internet class (standard)
  • TTL: Time to live in seconds
  • Class: Usually IN (Internet)

Practice Problems

0/3solved
Build DNS Component

Create a reusable React component implementing DNS. Include proper state management and accessibility.

Solution
// Production-ready component with:
// - Proper TypeScript types
// - Accessibility (ARIA)
// - Error boundaries
// - Loading states
// - Memoization where needed
DNS Testing

Write unit and integration tests for DNS using React Testing Library.

Solution
// Test coverage:
// 1. Rendering tests
// 2. Interaction tests
// 3. Edge case tests
// 4. Accessibility tests
DNS Performance

Optimize DNS for performance. Consider memoization, code splitting, and bundle size.

Solution
// Optimization techniques:
// 1. React.memo / useMemo / useCallback
// 2. Code splitting with lazy()
// 3. Virtual scrolling for lists
// 4. Image lazy loading
// 5. Bundle analysis

Quiz

1. What is the primary purpose of DNS?

Question 1 options

2. What does a CNAME record do?

Question 2 options

3. What is the correct order of DNS resolution?

Question 3 options

4. What does TTL mean in DNS?

Question 4 options

Flashcards

Question

What is DNS?

Answer

Domain Name System - translates domain names (google.com) to IP addresses (142.250.80.46).

Question

What is the difference between A and AAAA records?

Answer

A records map to IPv4 addresses (32-bit). AAAA records map to IPv6 addresses (128-bit).

Question

What is a CNAME record?

Answer

A CNAME (Canonical Name) creates an alias pointing one domain to another domain (e.g., www.example.com → example.com).

Question

What is DNS propagation?

Answer

The time it takes for DNS changes to spread across the internet. Can take minutes to 48 hours depending on TTL.

Question

What is DNS?

Answer

DNS is a key concept in frontend development.

Revision Notes

Key Takeaways

  • 1.DNS translates domain names to IP addresses
  • 2.DNS resolution follows a hierarchical query chain
  • 3.Different record types serve different purposes
  • 4.TTL controls how long DNS records are cached
  • 5.DNS propagation can take time when records change

Interview Tips

  • Walk through the full DNS resolution process
  • Know the difference between A, AAAA, CNAME, and MX records
  • Explain DNS caching and why it matters
  • Understand TTL and its impact on DNS updates

Cheat Sheet

DNS Cheat Sheet

What DNS Does:

  • Translates domain names → IP addresses
  • Like a phonebook for the internet

Resolution Flow:

  1. Browser/OS Cache
  2. ISP Resolver
  3. Root Nameserver (.)
  4. TLD Nameserver (.com)
  5. Authoritative Nameserver
  6. Return IP address

Record Types:

  • A: Domain → IPv4
  • AAAA: Domain → IPv6
  • CNAME: Domain alias → another domain
  • MX: Mail server
  • NS: Nameserver
  • TXT: Text info (SPF, DKIM)

TTL (Time To Live):

  • How long records are cached
  • Lower = faster updates, more queries
  • Higher = less queries, slower updates