What is DNS?

Free preview 6 min to read

The internet's phone book

Every device on the internet has an IP address: a number like 198.51.100.34. But humans don't think in numbers. We think in names: google.com, github.com, myapp.com.

The Domain Name System (DNS) is the service that translates human-readable domain names into machine-readable IP addresses. Without DNS, you'd have to memorize IP addresses for every website you visit.

You type:     google.com
DNS returns:  142.250.80.46
Browser uses: 142.250.80.46 to make a TCP connection

DNS is one of the most critical pieces of internet infrastructure. If DNS goes down, the internet effectively stops working: even though every server is still running. People can't find them.


Why not use IP addresses directly?

You could use IP addresses directly. Try http://142.250.80.46 in your browser: Google answers (over HTTPS you'd get a certificate warning, since the certificate names google.com, not the IP). But there are critical problems:

Problem Why DNS Solves It
Memorability google.com is easier to remember than 142.250.80.46
IP changes Servers change IPs when they move. DNS updates the mapping without you knowing
Multiple servers One domain can point to many IPs for load balancing
Virtual hosting Many domains can share one IP (the Host header tells the server which site)
Branding Businesses need memorable, brandable names

The analogy: phone books and contacts

DNS works like the contacts app on your phone:

Contacts App                DNS
─────────────               ───
"Mom" → +1-555-0123         "google.com" → 142.250.80.46
"Work" → +1-555-0456        "github.com" → 140.82.121.4
"Pizza" → +1-555-0789       "myapp.com"  → 203.0.113.42

You don't memorize phone numbers: you look up names. DNS does the same for the internet.

But unlike your contacts app (which stores everything locally), DNS is a distributed system: no single server has all the answers. Instead, different servers are responsible for different parts of the naming hierarchy.


How DNS fits in the request lifecycle

DNS is the first step before any HTTP request can be made:

1. User types: https://myapp.com/courses
2. Browser asks DNS: "What's the IP of myapp.com?"
3. DNS responds: "203.0.113.42"
4. Browser connects to 203.0.113.42:443 (TCP handshake)
5. Browser sends HTTP request: GET /courses
6. Server responds with HTML
7. Browser renders the page

Without step 2-3, steps 4-7 can't happen. DNS is the bridge between human-readable URLs and machine-readable addresses.


DNS is a distributed database

The DNS system handles trillions of queries per day. No single server could handle that load. Instead, DNS uses a hierarchical, distributed architecture:

flowchart TB
  R["Root servers (.)<br>13 root server identities, anycast worldwide"]
  COM[".com TLD"]
  ORG[".org TLD"]
  BR[".br ccTLD"]
  R --> COM & ORG & BR
  COM --> G["google.com<br>nameserver"]
  COM --> H["github.com<br>nameserver"]
  ORG --> W["wikipedia.org<br>nameserver"]
  BR --> GB["google.com.br<br>nameserver"]

Each level is responsible for a portion of the namespace:

Level Responsibility Example
Root servers Know where to find TLD servers . (the invisible dot after every domain)
TLD servers Know where to find domain nameservers .com, .org, .br, .io
Authoritative nameservers Know the actual IP addresses ns1.google.com

We'll explore this hierarchy in detail in lesson 3.


DNS uses UDP (mostly)

As you learned in the TCP/IP course, DNS primarily uses UDP on port 53:

Browser → DNS Resolver (UDP port 53)
  Query: "What's the IP of myapp.com?"

DNS Resolver → Browser (UDP port 53)
  Response: "203.0.113.42"

Total: 2 packets, ~5ms

Why UDP?

  • DNS queries are small (fits in one packet)
  • Speed matters: DNS happens before every new connection
  • If the response is lost, the client asks again

DNS switches to TCP when:

  • The response is too big for UDP (over 512 bytes classically; EDNS0 raises that, often to 1232)
  • Zone transfers between DNS servers (AXFR)
  • DNSSEC validation requires larger payloads

DNS in your daily Rails work

You interact with DNS constantly as a Rails developer:

Task DNS Involvement
Running bin/rails server localhost resolves to 127.0.0.1 via /etc/hosts
Database connection host: localhost comes from /etc/hosts; a remote DB host → DNS lookup
Sending emails SMTP server hostname → DNS lookup
API calls (Net::HTTP) External API hostname → DNS lookup
Deploying Your domain → points to server IP via DNS
SSL certificates Domain ownership can be proven with a DNS record (or over HTTP)
# DNS resolution failed
SocketError: getaddrinfo: nodename nor servname provided, or not known
# → The domain name couldn't be resolved to an IP

# DNS timeout
Resolv::ResolvTimeout: DNS resolv timeout
# → DNS server didn't respond in time

Key DNS terminology

Term Meaning
Domain name Human-readable address (e.g., myapp.com)
IP address Machine-readable address (e.g., 203.0.113.42)
DNS query A request to translate a domain to an IP
DNS response The answer containing the IP address
Resolver The DNS client that sends queries (your OS or ISP)
Nameserver A DNS server that answers queries
Record A single entry in DNS (e.g., myapp.com → 203.0.113.42)
TLD Top-Level Domain (.com, .org, .br)
TTL Time To Live: how long to cache a DNS answer
Propagation Time for DNS changes to spread across the internet

Summary

Concept Key Point
DNS Translates domain names to IP addresses
Why it exists Humans remember names, computers need numbers
Distributed system No single server has all answers: hierarchical delegation
Uses UDP port 53 Fast, small queries: if lost, just re-ask
First step in any request DNS happens before TCP handshake and HTTP
Critical infrastructure If DNS fails, the internet appears broken
Rails connection Every HTTP call, database connection, and email involves DNS
Lesson 1 of 7 · free

Keep going with lesson 2

Domain name structure

Breaks a domain name into root, TLD, SLD and subdomains, and covers FQDNs, apex domains and registration.

A free account also gives you the quizzes, your progress and notes, and the discussion.

Type to start searching...