Overview
DNS (Domain Name System) is the “phonebook of the internet.” It translates human-readable domain names (e.g., google.com) into machine-readable IP addresses (e.g., 142.250.190.46).
Core Concepts
- Hierarchical Namespace:
- Root Zone: The top of the hierarchy (
.). - TLD (Top-Level Domain):
.com,.org,.net,.io. - Authoritative Name Server: The final server in the chain that holds the actual IP record for the domain.
- Root Zone: The top of the hierarchy (
- DNS Record Types:
- A Record: Maps a hostname to an IPv4 address.
- AAAA Record: Maps a hostname to an IPv6 address.
- CNAME: An alias for another domain name.
- MX Record: Specifies the mail server for the domain.
- TXT Record: Used for verification (e.g., SPF, DKIM).
- Resolution Process:
- Recursive Resolver: The server that does the work of searching for the IP (usually provided by the ISP).
- Iterative Query: The resolver asks the Root, then TLD, then Authoritative server until the IP is found.
- Caching: To speed up resolution, DNS records are cached at various levels (browser, OS, resolver).
Code Examples
# Digging a domain to see its records
dig google.com A
dig google.com MX
# Checking the local hosts file (overrides DNS)
cat /etc/hosts
Use Cases
- User Experience: Allowing users to remember names instead of strings of numbers.
- Load Balancing: Using a single domain name to point to multiple different IP addresses (Round Robin DNS).
- Service Discovery: Using SRV records to find services in a network.
Gotchas
- DNS Propagation: When you change a DNS record, it can take hours (or days) to reach all resolvers worldwide due to caching (TTL – Time To Live).
- DNS Spoofing/Poisoning: An attacker inserting fake records into a resolver’s cache to redirect users to a malicious site.
