How DNS Works from Start to Finish
-
You type a website like example.com into your browser and hit Enter.
-
The browser wants to load the website: but it needs the IP address of that domain (e.g., 93.184.216.34) to connect to the server.
-
So, it asks: “What’s the IP address of example.com?” This question starts the DNS (Domain Name System) lookup.
Step-by-step Resolution Begins:
-
First, the browser checks if it already has the IP saved in its DNS cache (from a previous visit).
-
If not, it asks the operating system (like Windows, macOS, or Linux): “Hey, do you know the IP?”
-
If the OS doesn’t know, it sends the question to a DNS Resolver: usually provided by your ISP, or something like Google’s 8.8.8.8 or Cloudflare’s 1.1.1.1.
Now the Real Lookup Begins:
- The resolver checks its own cache. If no luck, it starts asking other DNS servers, starting from the top:
1. Root Server
-
The resolver first asks a Root DNS Server: “Who handles domains that end with .com?”
- There are 13 sets of root servers globally.
- They don’t give final answers: just directions.
2. TLD Server
-
The root server replies: “Ask the TLD (Top-Level Domain) server for .com domains.”
- TLD = the last part of the domain, like .com, .net, .org, .in, etc.
- Each TLD has its own DNS servers.
-
So now the resolver contacts a .com TLD server, and asks: “Hey, where can I find example.com?“
3. Authoritative DNS Server
-
The TLD server responds: “Ask the authoritative DNS server for example.com: it has the actual IP.”
a. This server is usually managed by your hosting provider (like GoDaddy, AWS Route53, Cloudflare, etc.)
-
The resolver now finally asks the authoritative server: “What is the IP address of example.com?”
-
And finally, this server replies with the correct IP: “It’s 93.184.216.34.”
-
The resolver sends the IP back to your operating system.
-
Your OS sends it to the browser.
-
Now the browser knows where to connect and makes an HTTP request to that IP address: and the website loads.
-
The resolver stores (caches) this IP for a while: so the next time you (or someone else nearby) visits example.com, it doesn’t have to look it up again.
-
The caching is controlled by a setting called TTL (Time To Live): the site owner decides how long others should remember the IP.
-
There are different types of DNS records:
- A - IP address of a domain
- CNAME - Alias to another domain
- MX - Mail server
- TXT - Misc info like SPF, verification, etc.
DNS Technical Deep Dive
DNS Record Types in Detail
DNS supports numerous record types, each with specific purposes:
-
A Record:
- Maps hostname to IPv4 address
- Format:
example.com. 3600 IN A 93.184.216.34
- Multiple A records enable round-robin load balancing
- Often has relatively short TTL for flexibility
-
AAAA Record:
- Maps hostname to IPv6 address
- Format:
example.com. 3600 IN AAAA 2606:2800:220:1:248:1893:25c8:1946
- Modern sites implement both A and AAAA for dual-stack support
-
CNAME Record:
- Creates alias pointing to another name
- Format:
www.example.com. 3600 IN CNAME example.com.
- Cannot coexist with other records for same name
- Cannot be used at zone apex (root domain)
-
MX Record:
- Specifies mail servers for domain
- Includes priority value (lower numbers = higher priority)
- Format:
example.com. 3600 IN MX 10 mail.example.com.
- Multiple MX records provide mail server redundancy
-
TXT Record:
- Stores arbitrary text data
- Used for domain verification, SPF, DKIM, DMARC
- Format:
example.com. 3600 IN TXT "v=spf1 include:_spf.example.com ~all"
- Maximum 255 characters per string (can be chunked)
-
NS Record:
- Delegates zone to authoritative nameservers
- Format:
example.com. 86400 IN NS ns1.example.com.
- Typically set at registrar level
- Minimum of two NS records recommended for redundancy
-
SOA Record:
- Start of Authority - contains administrative information
- Only one SOA record per zone
- Contains serial number, refresh intervals, negative caching TTL
- Format:
example.com. 86400 IN SOA ns1.example.com. admin.example.com. ( 2023121501 ; serial 7200 ; refresh 3600 ; retry 1209600 ; expire 3600 ) ; minimum TTL
-
SRV Record:
- Specifies service location (port and hostname)
- Used for VoIP, IM, and other services
- Format:
_sip._tcp.example.com. 3600 IN SRV 10 60 5060 sipserver.example.com.
- Includes priority, weight, port, and target fields
-
CAA Record:
- Certificate Authority Authorization
- Restricts which CAs can issue certificates
- Format:
example.com. 3600 IN CAA 0 issue "letsencrypt.org"
- Helps prevent unauthorized certificate issuance
-
PTR Record:
- Reverse DNS lookup (IP to name)
- Format:
34.216.184.93.in-addr.arpa. 3600 IN PTR example.com.
- Used for reputation systems and verification
DNS Protocol Technical Details
DNS operates primarily over UDP with TCP fallback:
-
Message Format:
- 12-byte header containing query ID, flags, and counts
- Question section with QNAME, QTYPE, and QCLASS
- Answer section containing resource records
- Authority section with NS records
- Additional section with related records
- Maximum UDP packet size: 512 bytes (traditional) or 4096 bytes (EDNS0)
-
Query Types:
- Standard query: One question, expects direct answer
- Inverse query: Requests data matching specific answer (deprecated)
- Recursive query: Asks resolver to complete full resolution
- Non-recursive (iterative) query: Just wants best available information
-
Response Codes:
- NOERROR (0): No error condition
- FORMERR (1): Format error in query
- SERVFAIL (2): Server failure
- NXDOMAIN (3): Name does not exist
- NOTIMP (4): Not implemented
- REFUSED (5): Query refused
- Additional codes for DNSSEC and extensions
-
UDP vs TCP:
- UDP for standard queries (port 53)
- TCP for zone transfers and responses >512 bytes
- DNS over TLS (DoT): TCP port 853
- DNS over HTTPS (DoH): TCP port 443
DNS Infrastructure Organization
The global DNS system is a distributed hierarchical database:
-
Root Zone:
- Maintained by IANA (Internet Assigned Numbers Authority)
- 13 logical root server clusters (A through M)
- Each cluster has multiple physical servers using anycast
- Over 1000 physical servers worldwide
- Root zone file managed through controlled process
- Changes to root zone require multiple approvals
-
TLD Organization:
- gTLDs: Generic TLDs (.com, .org, .net) managed by registry operators
- ccTLDs: Country-code TLDs (.us, .uk, .jp) managed by country authorities
- New gTLDs: Recently added extensions (.app, .blog, .xyz)
- Special-use TLDs: Reserved for specific purposes (.localhost, .test)
- IDN TLDs: Internationalized domain names (e.g., .网址, .рф)
-
Registrar-Registry Model:
- Registry: Maintains authoritative database for TLD
- Registrar: Accredited entity that sells domains to public
- Separation of concerns for competition and security
DNS Resolution Mechanisms
DNS resolution can follow different paths:
-
Recursive Resolution:
- Client sends query to recursive resolver
- Resolver takes full responsibility for finding answer
- Performs multiple queries to different nameservers
- Returns complete answer to client
- Most client-facing resolvers operate recursively
-
Iterative Resolution:
- Client or resolver receives referrals to next nameserver
- Must follow chain of referrals itself
- Root and TLD servers typically offer iterative responses
- More efficient for DNS infrastructure
- Used between DNS servers
-
Forwarding:
- Resolver forwards query to another resolver
- May cache response before returning to client
- Common in enterprise environments
- Can create resolution chains
DNS Caching System
Caching happens at multiple levels for performance:
-
Cache Hierarchy:
- Browser cache: Shortest duration, user-specific
- Operating system cache: Shared by all applications
- Local network cache (router/gateway)
- ISP resolver cache: Shared by many customers
- Public resolver cache (8.8.8.8, 1.1.1.1)
-
TTL Mechanics:
- Defined per record in seconds
- Specifies maximum time to cache
- Actual cache duration may be shorter (resolver policy)
- TTL counter decrements while cached
- Zero TTL prevents caching entirely
-
Negative Caching:
- Caching of NXDOMAIN responses
- Prevents repeated queries for non-existent domains
- Controlled by SOA record’s minimum TTL
- Important for performance and DDoS mitigation
-
Cache Poisoning Protections:
- Query ID randomization
- Source port randomization
- Case randomization in queries
- DNSSEC validation
DNSSEC (DNS Security Extensions)
DNSSEC adds cryptographic authentication:
-
Digital Signatures:
- Each DNS record or set has digital signature (RRSIG)
- Signatures created with zone’s private key
- Verified using zone’s public key (DNSKEY)
- Chain of trust from root to leaf zones
-
Trust Anchor:
- Root zone DNSKEY is starting point of trust
- Distributed to resolvers via trusted channel
- DS (Delegation Signer) records link parent to child zone keys
-
Record Types:
- DNSKEY: Public key for zone
- RRSIG: Signature covering specific records
- DS: Delegation signature linking to child zone
- NSEC/NSEC3: Authenticated denial of existence
-
Zone Signing Process:
- ZSK (Zone Signing Key): Signs actual records
- KSK (Key Signing Key): Signs DNSKEY records
- Key rotation procedures for security
- Automated signing systems
DNS Performance Optimization
Various techniques improve DNS performance:
-
Anycast Routing:
- Same IP address announced from multiple locations
- BGP routing sends query to nearest instance
- Reduces latency and provides load balancing
- Improves resilience against DDoS attacks
- Used by root servers, TLD servers, and public resolvers
-
Response Rate Limiting:
- Detects and limits abnormally high query rates
- Prevents amplification attacks
- Implemented at authoritative nameservers
- Dynamic thresholds based on query patterns
-
Prefetching:
- Proactive resolution before actual need
- Implemented in browsers and resolvers
- Reduces perceived latency
- Based on links, DNS records in HTML, historic patterns
-
DNS Query Minimization:
- Reveals only necessary parts of query to each nameserver
- Improves privacy
- Reduces information leakage
- Standardized in RFC 7816
DNS-Based Services and Extensions
DNS has evolved beyond simple name resolution:
-
GeoDNS:
- Returns different answers based on client location
- Directs users to nearest server
- Implemented using DNS provider’s proprietary systems
- Uses Edns-Client-Subnet extension for accuracy
-
DNS-Based Load Balancing:
- Rotates between multiple IP addresses
- Health-checking removes failed servers
- Weighted responses direct traffic proportionally
- Low TTLs allow quick adjustments
-
DNS Firewalls:
- Block access to malicious domains
- RPZ (Response Policy Zones) define blocking rules
- Used for security and content filtering
- Implemented at resolver level
-
Dynamic DNS:
- Allows frequent updates to DNS records
- Used for home networks with dynamic IPs
- Update clients use protocols like RFC 2136 or proprietary APIs
- Enables hosting services on changing IP addresses