DNS

Backend · DevOps

Phonebook for the internet. Turns names into IP addresses.

What it is

When you type google.com, your computer doesn’t know where that is. DNS servers translate human-readable domain names into IP addresses that computers can route to.

The lookup chain

  1. Browser cache - already know it?
  2. OS cache - /etc/hosts or system DNS cache
  3. Router cache
  4. ISP’s DNS resolver
  5. Root nameservers → TLD nameservers → Authoritative nameservers

Record types

TypeWhat it doesExample
ADomain → IPv4example.com → 93.184.216.34
AAAADomain → IPv6example.com → 2606:2800:...
CNAMEAlias to another domainwww → example.com
MXMail server for domainmail.example.com
TXTArbitrary text (SPF, DKIM, verification)"v=spf1 include:..."
NSNameserver for domainns1.example.com

Common gotchas

  • TTL caching: Changed DNS? Might take hours to propagate. TTL controls this.
  • CNAME at root: Can’t have CNAME on naked domain (example.com). Use ALIAS/ANAME if provider supports it.
  • Trailing dots: example.com. (with dot) is fully qualified. Some tools care.

Debug commands

# Basic lookup
dig example.com
 
# Specific record type
dig example.com MX
 
# Trace full resolution path
dig +trace example.com
 
# Use specific DNS server
dig @8.8.8.8 example.com
 
# Quick and dirty
nslookup example.com

Glossary

DNS · TTL