4. DNS
Practice: five levels
Assignments
Five levels. Do them in order. Answers are in "Solutions" at the end, so try first.
Level 1: Think (no code)
A. Which record type would you add?
- Point
api.example.comat the server203.0.113.30. - Point
blog.example.comat a blogging platform that says "point your domain tohosting.blogplatform.net". - Receive email for
@example.comon two mail servers, with one as backup. - Prove to a search console that you own
example.com. - Give
example.coman IPv6 address.
B. True or false? Explain each.
- "After I change a DNS record, it's pushed to every server in the world within a few minutes."
- "If I give my site four A records, users will never reach a dead server."
- "I can make
example.com(the bare domain) a CNAME to my hosting provider."
Level 2: Calculate
Assume about 10,000 resolvers worldwide send your users' questions to your authoritative name servers.
- With a TTL of 300 seconds, about how many queries a second reach your authoritative servers?
- With a TTL of 60 seconds? With 1 day?
- A resolver is 10 ms from the user, and 30 ms from each of the root, TLD and authoritative servers. How long does a lookup take with an empty cache? With the answer already in the resolver's cache?
- You move to new servers. The record's TTL was 1 day and you didn't lower it. In the worst case, how long might some users keep going to the old servers?
Level 3: Build
Write a toy recursive resolver in Python, with no real network calls. Simulate the hierarchy with dictionaries: a root that refers .com to a TLD server, a TLD server that refers example.com to ns1.example.com, and an authoritative server with an A record for shop.example.com, an A record for example.com, and a CNAME www.example.com → example.com.
Your resolve(name, now) must:
- Walk root → TLD → authoritative on an empty cache (3 queries).
- Answer from the cache while the TTL hasn't run out (no new queries).
- Ask again after the TTL expires.
- Follow a CNAME to the final IP address.
- Return
Nonefor a name that doesn't exist, and cache that for a short time.
Level 4: Debug
The bookstore moves to new servers. The runbook says:
1. Start the new servers at 198.51.100.7.
2. Change the A record for shop.example.com to 198.51.100.7 (TTL: 86400)
3. Switch off the old servers at 203.0.113.20 immediately.
The next day, support is flooded: "the site's been down for me since yesterday." Monitoring shows the new servers are healthy.
- Find the bug. Explain step by step why some users can't reach the site.
- Rewrite the runbook.
Level 5: Design
The bookstore expands to users in India, Europe and the US. It will run servers in Mumbai, Frankfurt and Virginia.
Deliver:
- How DNS sends each user to a nearby region.
- What happens when the whole Frankfurt region goes down, and how fast users move.
- Your TTL choices for the main records, and why.
- How you protect the site if your DNS provider itself has an outage.
- One limit of DNS-based routing, and how you'd work around it.