DNS (Domain Name System)
Master the phonebook of the internet. Learn how human-readable names are translated into IP addresses.
π DNS: Domain Name System
DNS is the system that translates human-readable domain names (like google.com) into machine-readable IP addresses (like 142.250.190.46).
π‘ The Logic (ELI5)
Think of your Smartphone Contacts:
- You want to call "Mom."
- Your phone doesn't know what "Mom" is.
- It looks up "Mom" in your Contact List (DNS).
- It finds her phone number:
+1 555-123-4567. - Your phone dials the number, connecting you to her phone.
π The Deep Dive
How the lookup works
- Local Cache: Your browser/OS checks if it already knows the IP.
- Recursive Resolver: Usually your ISP's server. It starts the multi-step journey.
- Root Nameserver: Points to the Top-Level Domain (TLD) server (like
.com). - TLD Nameserver: Points to the Authoritative Nameserver for the specific domain.
- Authoritative Nameserver: The final source of truth that says "Yes,
google.comis at IP X."
DNS Records to Know
- A Record: Maps a name to an IPv4 address.
- AAAA Record: Maps a name to an IPv6 address.
- CNAME: Maps one name to another name (Alias).
- MX Record: Tells the internet where to send emails for that domain.
π― Interview Pulse
Use Case: Load Balancing (DNS Round Robin)
Did you know DNS can act as a simple Load Balancer? You can list 5 different IP addresses for the same www.myapp.com. The DNS server will rotate through them, sending users to different servers.
The "Latency" Cost
DNS lookups take time (sometimes 100ms+). This is why browsers and CDNs cache DNS results heavily. Keyword: TTL (Time To Live). This tells the internet how long to cache a DNS record before asking for it again.
Common Question
"What happens if I change my DNS today?" Answer: DNS Propagation. It can take up to 48 hours for the new IP to reach every server and user on Earth because of all the different layers of caching. π