DNS
What
Convert human-readable names to computer-usable addresses
Why
Because remembering 2001:0db8:85a3::8a2e:0370:7334 is hard
Load balancing by converting the same domain into multiple IPs
Service discovery by adding certain records (e.g. MX) to a domain
Hierarchical nature makes it scalable
Concepts
- Hierarchy:
- Root (.) → TLD (.com) → Second-level (example.com) → Subdomains www.example.com
- DNS records:
- A: IPv4
- AAAA: IPv6
- MX: Mail
- CNAME: Alias
- NS: Name server
- PTR: Reverse DNS
- TXT: Text (abused for a ton of stuff)
- SOA: Authority
- Recursive resolver
- Client-side program that recursively queries name servers until it finds an answer
- Does the full lookup work, like following referrals
- Iterative resolver:
- Returns referrals
- "I don't know the answer, but you should ask X"
- Authoritative nameserver:
- Server that has the definitive answers for a certain domain
- Root servers: the servers at the top of the hierarchy
a.root-servers.nettom.root-servers.net
- Caching and Time To Live are used to reduce latency and load
- Zone: administrative area of control
- Glue records: A records needed to prevent circular dependencies
- Query
example.com - Root: "ask ns1.example.com"
- But to query
ns1.exmaple.com, we need to ask the nameserver forexample.comfor the IP - Instead, add A/AAAA records to the parent zone for the nameservers
- So
.comTLD will have records forns1.example.com - Glue records are only needed when the nameserver is within the domain:
- NEEDED:
example.com. NS ns1.example.com - NO GLUE NEEDED
example.com. NS ns1.hosting-provider.net
- NEEDED:
- Query
How
- User types query
- Check local cache
- Query root server, will return NS record for the next level down
- Query TLD server, will return NS record again
- Query authoritative NS for domain in question
- Get result