SPF, DKIM and DMARC
The three records, and what each one proves.
Chapter 3 sent mail as a bank and nothing objected. These three records are the answer.
The problem all three solve
Anyone can write any From: header. The fix is bolted on, and it lives in DNS where the
domain owner controls it.
A domain that publishes none of them is the starting point — this returns nothing:
dig +short TXT _dmarc.neverssl.comThree records, three different claims:
| Record | Proves |
|---|---|
| SPF | this IP may send for this domain |
| DKIM | this message was signed by this domain |
| DMARC | one of those matches the From: the reader sees |
SPF
A TXT record on the domain, listing who may send:
dig +short TXT google.com | grep spf1include: delegates to another record, authorising a provider without listing its IPs:
dig +short TXT _spf.google.comEach include: is another DNS lookup, and SPF allows ten in total. GitHub is at eight:
dig +short TXT github.com | grep -o 'include:' | wc -l | tr -d ' 'Reading an SPF record
The last term says what to do with everything not listed:
| Term | Means |
|---|---|
-all |
hard fail — reject |
~all |
soft fail — accept but mark |
?all |
neutral — no opinion |
+all |
pass everything, which is no policy |
Both are in use on real domains:
for d in google.com cloudflare.com; do
printf '%-14s ' $d
dig +short TXT $d | grep -o 'spf1.*' | grep -oE '[-~?+]all' | head -1
doneWhat SPF does not cover
SPF checks the envelope sender, not the From: a reader sees. Chapter 3’s spoof
passes SPF if evil.local has a valid record.
It also breaks on forwarding: the forwarder’s IP is not in your record, so a legitimately forwarded message fails. SPF alone was never enough.
DKIM
A signature over selected headers and the body, carried in a DKIM-Signature header. The
public key lives in DNS:
dig +short TXT google._domainkey.github.com | grep -oE 'v=DKIM1; k=rsa'The receiver fetches that key, recomputes the signature, and compares. A match proves nothing was altered since signing.
DKIM survives forwarding, because the signature travels with the message. That is the practical argument for having both.
The selector
google._domainkey.github.com is a selector plus a fixed suffix. It lets one domain
publish many keys — one per provider, a new one per rotation.
A selector that does not exist returns nothing, which is a failed verification:
dig +short TXT nonexistent._domainkey.google.comDMARC
A record at _dmarc.<domain> saying what to do when the other two fail:
dig +short TXT _dmarc.github.comp= is the policy for the domain, sp= for its subdomains:
dig +short TXT _dmarc.github.com \
| grep -oE '[; ]s?p=[a-z]+' | tr -d '; ' | xargsGitHub quarantines its own mail and rejects anything claiming to be a subdomain.
Alignment
The part that makes DMARC work, and why the other two were not enough.
SPF authenticates MAIL FROM:, DKIM authenticates the signing domain. DMARC requires
one of them to match the From: the reader sees.
| Check | Looks at | Aligns when |
|---|---|---|
| SPF | MAIL FROM: domain |
it matches From: |
| DKIM | the d= in the signature |
it matches From: |
Chapter 3’s spoof had MAIL FROM:<[email protected]> and From: [email protected]:
python3 -c '
env, hdr = "evil.local", "bank.example"
print("envelope:", env)
print("header: ", hdr)
print("aligned: ", env == hdr)'Choosing a policy
Three values, and all three are in production use:
for d in google.com amazon.com; do
printf '%-14s ' $d
dig +short TXT _dmarc.$d | grep -oE 'p=[a-z]+' | head -1
done| Policy | Receiver does |
|---|---|
p=none |
nothing — report only |
p=quarantine |
file it as spam |
p=reject |
refuse it outright |
Start at none, read the reports for a month, then move up. Going straight to reject
blocks mail from systems you forgot about.
Reports and ARC
rua= is where aggregate reports go — a daily XML summary naming every IP that sent as
your domain.
The reports are the point of p=none: they name your own systems that would be blocked,
before you block them.
ARC exists because forwarding breaks the other two. A list that rewrites headers destroys the signature and fails SPF; ARC records what each hop saw.