Networking · Lesson 6 of 14
DNS: the internet’s phone book
How DNS turns names into IP addresses: resolvers, record types, caching and TTL, with a real Pi-hole troubleshooting story and a DNS simulator.
⏱ 16 min🎯 Beginner🧪 Hands-on practice🎬 Video
By the end, you’ll be able to…
- Explain what a DNS resolver does and who it asks
- Recognise common record types: A, AAAA, CNAME, MX and TXT
- Use nslookup to ask a specific resolver, and explain why answers can differ
Key words
- DNS
- Domain Name System: turns human-friendly names into IP addresses and other information.
- Resolver
- The DNS server your device asks. It finds the answer for you and caches it.
- Record
- One piece of DNS data, like an A record that maps a name to an IPv4 address.
- TTL
- Time to live: how many seconds an answer may be cached.
- Authoritative server
- The DNS server that holds the official records for a domain.
A real problem first: the ad blocker that almost worked
When I set up Pi-hole (a DNS-based ad blocker) on a Raspberry Pi, it was blocking ads… but my computer kept showing them anyway. Here’s what I saw. Can you spot why?
Asking the computer’s default resolver
> nslookup ads.example
Server: dns.google
Answer: 192.0.2.20
Asking Pi-hole directly
> nslookup ads.example 192.168.1.185
Server: pi.hole
Answer: 0.0.0.0
Reveal the answer
The computer’s default resolver was still Google’s DNS, not the Pi-hole. The second command only asked Pi-hole for that one lookup, and Pi-hole did block it (answering 0.0.0.0). The fix was to set the computer, or the router’s DHCP settings, to use the Pi-hole as its DNS server.
To understand why, let’s look at how DNS works.
Why DNS exists
Computers route traffic using IP addresses like 192.0.2.10. Humans remember names like example.com. DNS is the system that connects the two. It’s distributed: no single server knows everything.
How a lookup works
- Your browser checks its own cache, then asks the operating system.
- The OS asks its configured resolver. At home that’s usually your router, your ISP, or a public resolver like
1.1.1.1or8.8.8.8. - If the resolver doesn’t have the answer cached, it asks a root server: “who handles
.com?” - The
.comservers say: “ask example.com’s authoritative name servers.” - The authoritative server gives the real answer. The resolver caches it for the TTL and passes it back to you.
That all happens in milliseconds. Thanks to caching, most lookups never need steps 3 to 5.
Common record types
| Type | Holds | Example |
|---|---|---|
| A | IPv4 address | example.com → 192.0.2.10 |
| AAAA | IPv6 address | example.com → 2001:db8::10 |
| CNAME | An alias to another name | www.example.com → example.com |
| MX | Mail server for the domain | example.com → mail.example.com |
| TXT | Text, often for email security and verification | v=spf1 … |
| NS | Which servers are authoritative | a.iana-servers.net |
The addresses above come from ranges reserved for documentation. Run the commands below to see the real, current answers.
Why DNS matters for security
- Blocking: tools like Pi-hole block ads and known-bad domains by answering with nothing useful.
- Visibility: DNS logs show which domains devices tried to reach. That’s gold for defenders investigating malware.
- Attacks: if attackers can change which resolver you use, or poison a cache, they can send you to a fake site. HTTPS certificates are a key defence here.
- Privacy: classic DNS is unencrypted. DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt lookups.
Try it yourself
# Ask your default resolver
nslookup example.com
# Ask a specific resolver (Cloudflare's public DNS)
nslookup example.com 1.1.1.1
# On macOS/Linux, dig gives more detail
dig example.com A
dig example.com MX +short
🧪 Hands-on
Practice
Choose which resolver to ask and which domain to look up. See how the answer changes, just like in the Pi-hole story.
🎬 Watch
Video: The Internet: IP Addresses & DNS
Video by Code.org, hosted on YouTube. It loads only when you press play.
✅ Check yourself
Quick quiz
🔗 Go further
Trustworthy resources
- Cloudflare: What is DNS? Beginner-friendly DNS explainer with diagrams.
- Pi-hole documentation Set up your own network-wide DNS filter.
- Pi-hole source code Open source on GitHub.