DNS originally used UDP with a 512-byte limit. EDNS(0) extended this, but UDP fragmentation remains problematic. Understanding response sizes prevents resolution failures.
UDP Size Limits and Fragmentation:
- Original DNS: 512 bytes maximum (RFC 1035)
- EDNS(0): Advertises larger buffer sizes (RFC 6891)
- Safe UDP size: ~1232 bytes (avoids fragmentation)
- MTU considerations: 1500-byte Ethernet MTU - IP/UDP headers = ~1472 usable
- Conservative limit: 1232 bytes accounts for tunneling overhead (VPN, IPv6-in-IPv4)
Why Fragmentation is Problematic:
- Firewalls: Many drop fragmented UDP packets for security
- Routers: Some discard fragments to prevent attacks
- Networks: Fragments can be lost independently, breaking reassembly
- Path MTU issues: ICMP "Packet Too Big" messages often blocked
- Result: DNS query timeout, fallback to TCP (slower)
DNS Packet Size Calculation:
- Header: 12 bytes (fixed)
- Question section: Name (variable) + type (2) + class (2)
- Answer section: Records with name, type, class, TTL, data length, data
- Authority section: Optional NS records
- Additional section: Optional A/AAAA for NS, EDNS OPT pseudo-record
Record Size Components:
- Name: Compressed or uncompressed (1-255 bytes typically)
- Type: 2 bytes (A=1, AAAA=28, TXT=16, etc.)
- Class: 2 bytes (IN=1)
- TTL: 4 bytes
- RDLENGTH: 2 bytes
- RDATA: Variable (4 bytes for A, 16 for AAAA, etc.)
Example Size Estimates:
- A record: ~16 bytes (name compressed) + 4 bytes (IPv4) = 20 bytes
- AAAA record: ~16 bytes + 16 bytes (IPv6) = 32 bytes
- MX record: ~16 bytes + 2 (priority) + domain (~20) = 38 bytes
- TXT record: ~16 bytes + text length (variable, often 100-500 bytes)
Fragmentation Risk Levels:
- Low (< 1232 bytes): Safe for UDP, no fragmentation expected
- Medium (1232-1472 bytes): May fragment on some networks, generally works
- High (> 1472 bytes): Will fragment, high risk of delivery failure
- Very High (> 4096 bytes): Almost certainly will fail UDP, TCP fallback required
DNSSEC Impact on Size:
- RRSIG records add 100-300 bytes per signed RRset
- DNSKEY records add 200-500 bytes
- DS records add 50-100 bytes
- DNSSEC can easily push responses over 1232 bytes
- Many zones with DNSSEC require TCP fallback
TCP Fallback Process:
- Resolver sends UDP query with EDNS(0) buffer size (e.g., 4096)
- Server responds, but response > 1232 bytes fragments
- Fragments are dropped by firewall or lost in transit
- Resolver times out (typically 2-5 seconds)
- Resolver retries with TCP (adds latency)
- TCP query succeeds but is slower (handshake + transmission)
Optimization Strategies:
- Reduce record count: Return only essential records in answer section
- Shorter names: Use shorter domain names where possible
- Split TXT records: Break long TXT into multiple smaller records
- Trim authority section: Omit NS records if not essential
- Minimize additional section: Rely on resolver's cache for glue records
- EDNS(0) buffer size: Advertise realistic sizes (1232-4096)
Common Problem Scenarios:
- Large SPF records: "v=spf1 include:... include:... ~all" with many includes
- DKIM keys: Long RSA public keys in TXT records (>512 characters)
- Multiple A records: 20+ A records for load balancing
- DNSSEC signed zones: RRSIG adds significant overhead
- CAA records: Multiple CAA records with long properties
EDNS(0) Buffer Size Recommendations:
- Resolvers should advertise: 1232 bytes (modern recommendation, RFC 6891 update)
- Authoritative servers: Should truncate (TC bit) if response > advertised buffer
- Avoid large buffers: 4096-byte buffers encourage responses that will fragment
- Flag Day 2020: Industry moved to 1232-byte default to reduce fragmentation
Testing and Verification:
- Use dig +bufsize=1232 +ignore to test UDP response size
- Check for TC (truncated) flag in response
- Monitor resolver logs for TCP fallback frequency
- Test from multiple network locations (home, mobile, cloud)
Best Practices:
- Keep DNS responses under 1232 bytes when possible
- Test response sizes before deploying DNSSEC
- Split overly long TXT records into multiple records
- Use shorter domain names in critical paths
- Monitor for increased TCP fallback after DNS changes
- Consider DNS over TCP for zones that consistently exceed limits