DNS Records, SPF & DMARC Email Security Explained
The Domain Name System (DNS) does far more than point websites to IP addresses — it also governs where your email is delivered and publishes the cryptographic and policy records that prevent attackers from impersonating your domain in phishing campaigns.
1. How a DNS Query Resolves Step by Step
When your browser looks up api.example.com and the answer is not already cached, your device contacts a recursive resolver (provided by your ISP or a public resolver like 1.1.1.1 or 8.8.8.8). That resolver walks the global DNS hierarchy in milliseconds:
- Root Nameservers: Direct the resolver to the TLD servers responsible for
.com. - TLD Nameservers (
.com): Return the domain's authoritativeNSrecords (for instance, Cloudflare or Route 53). - Authoritative Nameservers: Return the exact
A,AAAA,MX, orTXTrecord along with its Time To Live (TTL) value in seconds.
2. Planning Zero-Downtime Migrations with TTL
DNS changes do not "propagate" instantly across the globe — resolvers simply hold the old answer until its TTL expires. If your A record currently has a TTL of 86400 (24 hours) and you swap IPs without preparing, visitors behind caching resolvers may hit the old server for up to a full day.
Best practice before a server move: Lower the record's TTL to 300 seconds (5 minutes) at least 24 hours before the migration window. Perform the cutover, confirm traffic shifts cleanly within minutes, and then raise the TTL back to 3600–14400 seconds to reduce lookup latency.
3. Stopping Email Spoofing: SPF, DKIM, and DMARC
The original SMTP email protocol did not verify whether the server transmitting a message was actually authorized to use the sender's domain in the From: header. Modern inbox providers (including Gmail, Yahoo, and Microsoft 365) now strongly require three DNS-based authentication layers — and routinely bounce or spam-folder unauthenticated mail.
SPF (Sender Policy Framework)
Published as a TXT record on your root domain, SPF lists every IP range and mail service allowed to send email on your behalf:
v=spf1 include:_spf.google.com include:sendgrid.net -all
-all(Hard Fail): Tells receivers to reject mail from any server not listed.~all(Soft Fail): Marks unauthorized senders as suspicious; commonly paired with DMARC enforcement.- Never use
+all: That explicitly permits every server on earth to spoof your domain. - Watch the 10-DNS-Lookup Limit: RFC 7208 caps SPF evaluation at 10 nested DNS lookups (
include,a,mx,redirect). Exceeding 10 causes a permanent error (permerror), breaking SPF completely. - Only one SPF record per domain: Publishing two separate
v=spf1TXT records invalidates both; merge all mechanisms into a single record.
DKIM (DomainKeys Identified Mail)
DKIM attaches a cryptographic digital signature to each outgoing email header. Your sending server signs the message with a private key, and receivers verify it against the public key published under a selector subdomain such as google._domainkey.example.com. Unlike SPF, DKIM survives email forwarding as long as the signed headers and body are not altered in transit.
DMARC (Domain-based Message Authentication, Reporting & Conformance)
Published as a TXT record at _dmarc.yourdomain.com, DMARC ties SPF and DKIM together by requiring domain alignment (the domain authenticated by SPF or DKIM must match the visible From: header) and telling receivers what action to take on failures:
_dmarc.example.com TXT "v=DMARC1; p=reject; rua=mailto:[email protected]; adkim=r; aspf=r"
4. Safe 3-Phase DMARC Rollout Plan
- Phase 1 — Monitor (
p=none): Publishv=DMARC1; p=none; rua=mailto:...and inspect XML aggregate reports for 2–4 weeks to discover every legitimate third-party sender (CRM, billing, helpdesk, newsletter tools) using your domain. - Phase 2 — Quarantine (
p=quarantine; pct=25→pct=100): Once all legitimate senders pass SPF/DKIM alignment, route failing messages to spam gradually using thepct=percentage tag. - Phase 3 — Reject (
p=reject): Block spoofed messages outright at the SMTP gateway so forged emails never reach recipients' inboxes.
v=spf1 -all) and strict DMARC (v=DMARC1; p=reject; sp=reject;).