DNS Lookups

"It's always DNS."

Half the networking problems you'll debug come down to DNS. Let's master the tools.

dig - The Gold Standard

Terminal
$dig google.com
;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 299 IN A 142.250.185.78

Short Answer

Terminal
$dig +short google.com
142.250.185.78

+short gives just the IP - perfect for scripts.

Query Specific Record Types

Terminal
$dig MX google.com +short
10 smtp.google.com. 20 smtp2.google.com.
$dig NS google.com +short
ns1.google.com. ns2.google.com.
$dig TXT google.com +short
"v=spf1 include:_spf.google.com ~all"

Common record types:

TypeContains
AIPv4 address
AAAAIPv6 address
MXMail servers
NSName servers
TXTText records (SPF, DKIM, etc.)
CNAMEAlias to another domain

Query Specific DNS Server

Terminal
$dig @8.8.8.8 google.com +short
142.250.185.78

@8.8.8.8 uses Google's DNS instead of system default. Useful for testing.

nslookup - Quick and Simple

Terminal
$nslookup google.com
Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: Name: google.com Address: 142.250.185.78

Use Specific Server

Terminal
$nslookup google.com 8.8.8.8
(uses Google's DNS)

host - Simplest Option

Terminal
$host google.com
google.com has address 142.250.185.78 google.com has IPv6 address 2607:f8b0:4004:800::200e google.com mail is handled by 10 smtp.google.com.
Terminal
$host 142.250.185.78
78.185.250.142.in-addr.arpa domain name pointer lga25s71-in-f14.1e100.net.

host IP does reverse DNS (IP to name).

Checking DNS Configuration

Terminal
$cat /etc/resolv.conf
nameserver 127.0.0.53 nameserver 8.8.8.8

This shows which DNS servers your system uses.

Troubleshooting DNS

Site Won't Load - Is It DNS?

Terminal
$dig example.com +short
(empty - no response)
$dig @8.8.8.8 example.com +short
93.184.216.34

Local DNS failed, Google's works โ†’ local DNS problem.

Wrong IP Being Returned

Terminal
$dig mysite.com +short
1.2.3.4
$# Expected 5.6.7.8 - DNS cache is stale

DNS Propagation

After changing DNS records, it can take hours to propagate. Test with different DNS servers to check propagation:

hljs bash
dig @8.8.8.8 site.com     # Google
dig @1.1.1.1 site.com     # Cloudflare
dig @9.9.9.9 site.com     # Quad9
Knowledge Check

How do you check if a DNS issue is with your local DNS server specifically?

Quick Reference

CommandPurpose
dig domainFull DNS query
dig +short domainJust the IP
dig @8.8.8.8 domainUse specific DNS server
dig MX domainMail server records
nslookup domainSimple lookup
host domainSimplest lookup
host IPReverse lookup

Key Takeaways

  • dig is the most powerful DNS tool
  • dig +short for quick IP lookups
  • Test different DNS servers to isolate problems
  • Check /etc/resolv.conf for DNS configuration
  • "It's always DNS" - check DNS first when debugging

Next: making HTTP requests with curl.