# DNS

> Understand how domain names resolve to IP addresses through recursive resolvers, root, TLD and authoritative servers, plus record types and caching. Free...

Canonical: https://www.internhack.in/roadmaps/tracks/cs-fundamentals/dns
Last updated: 2026-11-28

Understand how domain names resolve to IP addresses through recursive resolvers, root, TLD and authoritative servers, plus record types and caching.

Beginner · about 3 hours · difficulty 2/5

Learn first: [Transport Layer: TCP and UDP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/tcp-and-udp)

DNS is the internet's phone book: it turns `example.com` into an IP address. It is short to learn and appears in almost every "what happens when you type a URL" answer.

### Resolution step by step

- The browser checks its own cache, then the OS cache and the `hosts` file.
- The query goes to a **recursive resolver** (your ISP's, or a public one like 8.8.8.8 or 1.1.1.1).
- The resolver asks a **root server**, which points to the **TLD server** for `.com`, which points to the domain's **authoritative name server**, which returns the answer.
- The resolver caches the answer for its **TTL** and returns it. Recursive (resolver does the work for you) vs iterative (each server refers you onward) queries are a common question.

### Record types to know

- **A** (IPv4) and **AAAA** (IPv6).
- **CNAME**: an alias to another name (`www` pointing to the root domain or a CDN).
- **MX**: mail servers. **TXT**: verification and email security (SPF, DKIM). **NS**: authoritative name servers.

### Why it matters in engineering

- **TTL trade-off**: long TTLs mean fewer lookups but slow changes during a migration.
- DNS is used for simple load balancing and geo-routing (returning different IPs by region), which ties into system design.
- DNS runs mostly on **UDP port 53**, falling back to TCP for large responses.
- Security: DNS spoofing and cache poisoning, mitigated by DNSSEC; DNS over HTTPS for privacy.

Good enough to move on: you can explain the full resolution path with caching, pick the right record type for a scenario, and use `nslookup` or `dig` to inspect a domain.

## Key concepts

- **Resolver, root, TLD, authoritative**
- **Recursive vs iterative queries**
- **A, AAAA, CNAME, MX, TXT, NS records**
- **Caching and TTL**
- **DNS-based load balancing**
- **dig and nslookup**
- **DNS security and DNSSEC**

## Mini project

Use dig +trace on three domains and document each step of the resolution chain, then write a small script that sends a raw DNS query over UDP and parses the A records from the response.

## Check yourself

You changed your server's IP but some users still reach the old one for hours. What explains this and how would you plan the next migration?

## Free resources

- [Cloudflare Learning Center: What is DNS?](https://www.cloudflare.com/learning/dns/what-is-dns/) (Cloudflare)
- [How DNS Works (comic)](https://howdns.works/) (howdns.works)
- [MDN: What is a domain name?](https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Web_mechanics/What_is_a_domain_name) (MDN)

Previous: [Transport Layer: TCP and UDP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/tcp-and-udp) · Next: [HTTP, HTTPS and TLS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/http-and-https)

## More in Computer Networks

- [How the Internet Works: OSI and TCP/IP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-models)
- [IP Addressing, Subnetting and Routing](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/ip-addressing-routing)
- [Transport Layer: TCP and UDP](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/tcp-and-udp)
- [DNS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/dns)
- [HTTP, HTTPS and TLS](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/http-and-https)
- [Network Security Essentials](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/network-security-basics)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [CS Fundamentals and Placement Prep Roadmap](https://www.internhack.in/roadmaps/tracks/cs-fundamentals)
