DNS Records: The Phone Book of the Internet
When you type example.com, your browser needs an IP address. DNS (Domain Name System) translates domain names to IPs. Each DNS record type serves a specific purpose, and as a developer, you'll configure them when setting up domains, email, SSL, and deployments.
Record Types
| Type | Purpose | Example Value |
|---|---|---|
A | Maps domain to IPv4 address | 93.184.216.34 |
AAAA | Maps domain to IPv6 address | 2606:2800:220:1:248:1893:25c8:1946 |
CNAME | Alias — points domain to another domain | myapp.vercel.app |
MX | Mail server for the domain | 10 mail.example.com |
TXT | Arbitrary text (SPF, DKIM, verification) | v=spf1 include:_spf.google.com ~all |
NS | Nameserver — who manages DNS for this domain | ns1.cloudflare.com |
SRV | Service locator (port + host for a service) | 0 5 5060 sip.example.com |
CAA | Which CAs can issue SSL certs for this domain | 0 issue "letsencrypt.org" |
A Record
The most basic record. Points your domain to an IP:
example.com. A 93.184.216.34
api.example.com A 203.0.113.42Use A records when you know the exact IP of your server.
CNAME Record
Points a domain to another domain (alias):
www.example.com CNAME example.com
blog.example.com CNAME mysite.netlify.app
app.example.com CNAME myapp.vercel.appImportant: You cannot have a CNAME on the root domain (example.com). Use A records or ALIAS/ANAME records (Cloudflare supports this as "flattened CNAME").
MX Record
Tells other mail servers where to deliver email for your domain:
example.com MX 10 alt1.gmail-smtp-in.l.google.com
example.com MX 20 alt2.gmail-smtp-in.l.google.comThe number is priority — lower is preferred. If server 10 is down, mail goes to server 20.
TXT Record (Verification & Email Security)
# SPF — who can send email on behalf of your domain
example.com TXT "v=spf1 include:_spf.google.com ~all"
# DKIM — email signing key
default._domainkey.example.com TXT "v=DKIM1; k=rsa; p=MIGfMA0..."
# DMARC — what to do with failing emails
_dmarc.example.com TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"
# Domain verification (Google, Vercel, etc.)
example.com TXT "google-site-verification=abc123..."TTL (Time to Live)
How long DNS resolvers cache a record (in seconds):
| TTL Value | Duration | Use Case |
|---|---|---|
| 300 | 5 minutes | Records that change frequently, during migrations |
| 3600 | 1 hour | Standard for most records |
| 86400 | 24 hours | Stable records that rarely change |
Pro tip: Lower TTL before a migration so changes propagate faster. Raise it back after.
Debugging DNS
# Query A record
dig example.com A
# Query specific record type
dig example.com MX
dig example.com TXT
# Use a specific DNS server (bypass cache)
dig @8.8.8.8 example.com A
# Trace the full resolution path
dig +trace example.com
# Windows
nslookup example.com
nslookup -type=MX example.comCommon Setups
Custom domain on Vercel:
example.com A 76.76.21.21
www.example.com CNAME cname.vercel-dns.comCustom domain on Cloudflare Pages:
example.com CNAME your-project.pages.dev (proxied)Google Workspace email:
example.com MX 1 aspmx.l.google.com
example.com MX 5 alt1.aspmx.l.google.com
example.com TXT "v=spf1 include:_spf.google.com ~all"DNS lookup tool: DNS Lookup — query any domain's DNS records instantly.