SPF, DKIM and DMARC Explained: How to Check and Fix Your Email DNS Records

Mail Servers 9 min readUpdated Nov 17, 2026
3 views0 comments
A row of colourful rural mailboxes on wooden posts along a country road
Photo: Bernard Spragg. NZ from Christchurch, New Zealand / Wikimedia Commons (CC0, public domain). source

When email from your domain lands in spam, or is rejected with a message about authentication, the cause is usually not your message. It is three small DNS records: SPF, DKIM and DMARC. Together they let a receiving server check that a message really comes from you. This guide explains what each one does in plain language, shows the exact records, and gives you commands to check them from Linux, macOS and Windows.

The three records at a glance

Record What it answers Where it lives (DNS)
SPF Which servers are allowed to send mail for my domain? A TXT record on the domain itself, starting with v=spf1
DKIM Was this message signed by my domain, and was it changed on the way? A TXT record at selector._domainkey.yourdomain, starting with v=DKIM1
DMARC If SPF and DKIM fail, what should the receiver do, and who gets the reports? A TXT record at _dmarc.yourdomain, starting with v=DMARC1

All three are plain text records. You add them at the company that hosts your DNS (your registrar, your hosting provider or a service such as Cloudflare), not on the mail server.

How a receiving server uses them

  1. A message arrives. The server notes the IP address that delivered it and the domain in the envelope sender (the Return-Path).
  2. SPF: it looks up the SPF record of that domain and checks whether the delivering IP is on the list.
  3. DKIM: it reads the signature in the message headers, fetches the public key from DNS and checks the signature.
  4. DMARC: it looks up the DMARC record of the domain in the visible From address, checks that SPF or DKIM passed and matches that domain, and applies your policy if not.

That last step matters. The envelope sender and the visible From address can differ, and SPF alone only looks at the envelope. DMARC is what connects the checks to the address people actually see.

SPF: who may send

An SPF record is a list of permitted senders ending in a rule for everyone else. A typical record looks like this:

example.com.  TXT  "v=spf1 ip4:203.0.113.10 include:_spf.mailprovider.example ~all"
  • v=spf1 marks the record as SPF. It must come first.
  • ip4:203.0.113.10 allows one IPv4 address. Use ip4:203.0.113.0/24 for a range and ip6: for IPv6.
  • include:_spf.mailprovider.example allows whatever servers that provider lists in its own SPF record. This is how you authorise services such as a newsletter platform.
  • mx and a allow the servers behind your MX or A records.
  • ~all says what to do with everything else. -all means “fail” (reject), ~all means “softfail” (accept but mark suspicious), ?all means neutral. Never use +all, which allows the whole internet.

A domain can also hand its policy to another one with redirect=. At the time of writing, gmail.com does exactly that:

"v=spf1 redirect=_spf.google.com"

The two SPF rules people break

  • One SPF record per name. If you add a second v=spf1 record, SPF returns a permanent error and receivers may ignore both. When you need to authorise another service, add its include: to the existing record.
  • Ten DNS lookups at most. Each include, a, mx, exists and redirect costs a lookup, and so does everything nested inside an include. Past ten, SPF fails with a permanent error. ip4, ip6 and all are free, so replace unneeded includes with the IP ranges you actually use.

DKIM: the signature

With DKIM your mail server signs every outgoing message with a private key. The matching public key is published in DNS so anyone can verify the signature. The record name includes a selector, a label you choose, so you can have several keys at once:

selector1._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A..."
  • v=DKIM1 marks the record. k=rsa is the key type.
  • p= holds the public key. An empty p= means the key was revoked.
  • Use a 2048-bit key. Older 1024-bit keys still work but are considered weak.
  • Your provider or mail software generates the key pair and tells you the record to publish. Never publish the private key.
  • A 2048-bit key is longer than the 255 characters one DNS string can hold, so it is stored as several quoted strings in one record. Most DNS panels do this for you. If your panel complains, paste the value as the provider gave it.

To find which selector a message used, open its full headers and look at the DKIM-Signature line:

DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=selector1; ...

d= is the signing domain and s= is the selector. The public key is at s._domainkey.d.

DMARC: the policy and the reports

DMARC says what a receiver should do when a message fails both SPF and DKIM alignment, and where to send reports:

_dmarc.example.com.  TXT  "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com"
  • p= is the policy: none (monitor only, take no action), quarantine (treat as suspicious, usually the spam folder) or reject (refuse).
  • sp= sets a different policy for subdomains.
  • rua= is the address that receives daily aggregate reports (XML summaries sent by the big mailbox providers).
  • pct= applies the policy to only a percentage of failing mail while you gain confidence.
  • adkim and aspf set alignment to relaxed (r, the default) or strict (s).

Alignment means the domain that passed SPF (the envelope sender) or DKIM (the d= value) must match the domain in the visible From address. With relaxed alignment, mail.example.com matches example.com. DMARC passes if either SPF or DKIM passes and is aligned.

If the rua address belongs to a different domain than the one you are protecting, that other domain must publish a record authorising the reports. Using an address on the same domain avoids the problem.

A safe rollout

  1. Publish SPF and DKIM first and confirm they pass (see below).
  2. Add DMARC with p=none and a rua mailbox you actually read. Watch the reports for a couple of weeks. They show every service that sends as your domain, including ones you forgot.
  3. Fix any legitimate sender that fails.
  4. Move to p=quarantine, optionally with pct=25 rising to 100.
  5. When everything legitimate passes, move to p=reject.

Real domains do this too. At the time of writing, gmail.com publishes v=DMARC1; p=none; sp=quarantine; rua=mailto:mailauth-reports@google.com: monitor the main domain, quarantine failures on subdomains.

Check your records from the command line

Linux and macOS: dig

dig +short TXT example.com               # SPF lives with the other TXT records
dig +short TXT selector1._domainkey.example.com   # DKIM
dig +short TXT _dmarc.example.com        # DMARC

Example output (at the time of writing):

$ dig +short TXT gmail.com
"v=spf1 redirect=_spf.google.com"

$ dig +short TXT _dmarc.gmail.com
"v=DMARC1; p=none; sp=quarantine; rua=mailto:mailauth-reports@google.com"

Add @8.8.8.8 to ask a specific public resolver instead of your own, which helps when your local cache still shows an old value. For more on dig see our DNS troubleshooting guide.

Windows PowerShell

Resolve-DnsName -Name example.com -Type TXT
(Resolve-DnsName -Name _dmarc.gmail.com -Type TXT).Strings -join ''

The .Strings property holds the record text, and -join '' glues a value that was split into several strings back together. nslookup -type=TXT _dmarc.example.com works on every platform.

Read the verdict in a real message

The most useful test is a real one. Send a message from your domain to a Gmail address, open it, choose the three-dot menu and Show original. Gmail shows a summary such as SPF: PASS, DKIM: PASS, DMARC: PASS. In the raw headers the same result sits on the Authentication-Results line. Anything other than pass tells you which record to fix.

Common mistakes and fixes

Symptom Likely cause Fix
SPF permerror Two SPF records, or more than ten lookups Merge into one record. Replace includes with ip4 ranges where possible.
SPF fail for one service The service is not in your SPF record Add the include: the service documents.
DKIM fail or “no key” Wrong selector, record at the wrong name, or the key was cut when pasted Compare s= in the header with the record name. Re-copy the full key.
The record never appears The DNS panel added the domain twice, giving _dmarc.example.com.example.com Enter only _dmarc in panels that append the domain for you.
DMARC fails although SPF passes SPF passed for another domain (a provider’s), so it is not aligned Use a custom return-path or sign with DKIM using your own domain.
Legit mail rejected after p=reject Policy tightened before every sender was fixed Return to p=none, read the reports, fix the sender, tighten again.
Forwarded mail fails Forwarding changes the sending IP, so SPF fails Normal. DKIM usually survives forwarding, which is why you want both.

DNS changes can take time to spread. Records are cached for the TTL (time to live) shown in your DNS panel, often 300 to 3600 seconds, so give a new record up to an hour before you decide it does not work.

Domains that never send mail

Spoofers love domains that look unprotected. If a domain sends no email, say so. A “send nothing” SPF record is enough to start:

"v=spf1 -all"

The domain example.com publishes exactly this. Pair it with v=DMARC1; p=reject; at _dmarc and receivers will refuse anything claiming to come from that domain.

Checklist for a new sending domain

  1. Publish one SPF record that lists every service that sends for you.
  2. Turn on DKIM signing in your mail server or provider and publish the key it gives you (2048-bit).
  3. Publish _dmarc with p=none and a rua mailbox you read.
  4. Send a test to Gmail and confirm SPF, DKIM and DMARC all say pass.
  5. Make sure the server’s IP address has a matching reverse DNS (PTR) name. See our guide to DNS records for how records fit together.
  6. Review the DMARC reports for two weeks, then raise the policy.

Frequently asked questions

Do I need all three?

Yes. Each covers a gap in the others. Since 2024 Gmail and Yahoo require SPF, DKIM and DMARC from anyone sending in bulk, and they are good practice for small senders too.

Will DMARC stop all spoofing?

It stops others from sending mail that claims to come from your exact domain once the policy is reject. It does not stop look-alike domains such as examp1e.com.

Where do I read the reports?

Aggregate reports arrive as compressed XML attachments. They are hard to read by eye, so many people use a free DMARC report parser. A dedicated mailbox keeps them out of your daily inbox.

Why does my provider say “SPF is fine” but DMARC still fails?

Because SPF passing is not enough. The passing domain must also align with your From address. Check alignment, or rely on a DKIM signature made with your own domain.

Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

More tutorials like this

Leave a Comment

Your email address will not be published. Required fields are marked *

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top