DNS Networking Debugging

DNS Deep Dive: How Name Resolution Really Works

JW
James Wong
Infrastructure Architect
Feb 25, 2025
12 min read

What You'll Learn

A complete DNS deep dive — how name resolution works step by step, record types, TTL, caching, DNS debugging with dig and nslookup, and common DNS issues in cloud/K8s environments.

How DNS Resolution Works (Step by Step)

When you type google.com in your browser, a lot happens before you see any content. Here's the complete journey:

1
Browser Cache
Browser checks its own DNS cache. If cached and TTL not expired → done!
2
OS Cache
OS checks /etc/hosts file, then its local DNS cache (nscd/systemd-resolved).
3
Recursive Resolver (ISP/8.8.8.8)
Your configured DNS server (e.g., Google 8.8.8.8) receives the query and checks its cache.
4
Root Nameserver
Resolver queries one of 13 root nameservers (a.root-servers.net..m.root-servers.net). Responds with TLD nameserver address.
5
TLD Nameserver (.com)
The .com nameserver responds with the authoritative nameserver for google.com.
6
Authoritative Nameserver
Google's nameserver (ns1.google.com) returns the actual IP address for google.com.
7
Response Cached & Returned
IP is returned to browser and cached at each level. Browser connects to the IP.

DNS Record Types You Must Know

RecordPurposeExample
AMaps domain → IPv4 addressapp.example.com → 93.184.216.34
AAAAMaps domain → IPv6 addressapp.example.com → 2600:1f18::1
CNAMEAlias — maps domain → domainwww → app.example.com
MXMail server for the domainexample.com → mail.google.com (priority 10)
TXTText data (SPF, DKIM, verification)"v=spf1 include:_spf.google.com ~all"
NSNameserver for the domainexample.com → ns1.cloudflare.com
SOAStart of Authority — zone infoPrimary NS, admin email, serial, TTL
PTRReverse DNS — IP → domain93.184.216.34 → example.com
SRVService location (Kubernetes uses this!)_http._tcp.example.com → host port weight

DNS Debugging Tools

bash — DNS debugging commands
# dig — The most powerful DNS tool
dig google.com                          # Query A records
dig google.com A                        # Explicit record type
dig google.com MX                       # Mail server records
dig google.com NS                       # Nameservers
dig google.com ANY                      # All records
dig @8.8.8.8 google.com                # Query specific DNS server
dig google.com +short                   # Short output (just IPs)
dig google.com +trace                   # Trace full resolution path (⭐ very useful!)
dig -x 8.8.8.8                         # Reverse DNS lookup (PTR)
dig google.com +nocmd +noall +answer   # Clean answer-only output

# nslookup — Interactive or one-shot
nslookup google.com                    # Basic lookup
nslookup -type=MX google.com          # MX records
nslookup google.com 8.8.8.8           # Use specific server
nslookup                               # Interactive mode (type: set type=MX)

# host — Simple lookup
host google.com
host -t MX google.com
host 8.8.8.8                           # Reverse lookup

# Check system DNS config
cat /etc/resolv.conf                    # Configured DNS servers
cat /etc/hosts                          # Local hostname overrides
systemd-resolve --status               # systemd-resolved status
resolvectl query google.com            # Query via systemd-resolved

DNS in Kubernetes

Kubernetes DNS patterns
# Kubernetes DNS naming patterns:
# ..svc.cluster.local

# Within the same namespace:
curl http://my-service

# Cross-namespace:
curl http://my-service.production.svc.cluster.local

# Debug DNS inside a pod
kubectl run debug-dns --rm -it --image=busybox -- nslookup kubernetes
kubectl exec -it my-pod -- nslookup my-service.default.svc.cluster.local

# Check CoreDNS (the K8s DNS server)
kubectl get pods -n kube-system -l k8s-app=kube-dns
kubectl logs -n kube-system -l k8s-app=kube-dns

# Debug DNS resolution from a pod
kubectl run netshoot --rm -it --image=nicolaka/netshoot -- bash
# Inside pod:
dig my-service.production.svc.cluster.local
nslookup my-service

Common DNS Issues & Fixes

❌ NXDOMAIN — Domain does not exist

The domain doesn't exist in DNS. Check typos, ensure the record was created, propagation can take up to 48h.

⏱ Slow DNS resolution

Try dig +time=2 +tries=1 google.com. If slow, check /etc/resolv.conf, try a different DNS server (8.8.8.8), or check network routing to DNS server.

🔄 Old IP cached after DNS change

Wait for TTL to expire. Check TTL with dig google.com | grep -i ttl. Flush local cache: systemd-resolve --flush-caches

Keep Reading

D
DevOps

Docker Networking Demystified: Bridge, Host & Overlay

8 min read Read More
C
Cloud

AWS IAM Roles vs Users vs Policies

10 min read Read More
P
Programming

Understanding Python's GIL & Multiprocessing

14 min read Read More