
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
- A message arrives. The server notes the IP address that delivered it and the domain in the envelope sender (the Return-Path).
- SPF: it looks up the SPF record of that domain and checks whether the delivering IP is on the list.
- DKIM: it reads the signature in the message headers, fetches the public key from DNS and checks the signature.
- 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=spf1marks the record as SPF. It must come first.ip4:203.0.113.10allows one IPv4 address. Useip4:203.0.113.0/24for a range andip6:for IPv6.include:_spf.mailprovider.exampleallows whatever servers that provider lists in its own SPF record. This is how you authorise services such as a newsletter platform.mxandaallow the servers behind your MX or A records.~allsays what to do with everything else.-allmeans “fail” (reject),~allmeans “softfail” (accept but mark suspicious),?allmeans 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=spf1record, SPF returns a permanent error and receivers may ignore both. When you need to authorise another service, add itsinclude:to the existing record. - Ten DNS lookups at most. Each
include,a,mx,existsandredirectcosts a lookup, and so does everything nested inside an include. Past ten, SPF fails with a permanent error.ip4,ip6andallare 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=DKIM1marks the record.k=rsais the key type.p=holds the public key. An emptyp=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) orreject(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.adkimandaspfset 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
- Publish SPF and DKIM first and confirm they pass (see below).
- Add DMARC with
p=noneand aruamailbox you actually read. Watch the reports for a couple of weeks. They show every service that sends as your domain, including ones you forgot. - Fix any legitimate sender that fails.
- Move to
p=quarantine, optionally withpct=25rising to 100. - 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
- Publish one SPF record that lists every service that sends for you.
- Turn on DKIM signing in your mail server or provider and publish the key it gives you (2048-bit).
- Publish
_dmarcwithp=noneand aruamailbox you read. - Send a test to Gmail and confirm SPF, DKIM and DMARC all say
pass. - 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.
- 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.
More tutorials like this
Linux Users, Groups and sudo: useradd, usermod, passwd and visudo
Create and manage Linux users and groups with useradd and usermod, set password rules with chage, and give administrator rights safely with sudo and…
Linux File Permissions Explained: chmod, chown, umask and the rwx Notation
Read the rwx permission string, use chmod, chown and umask with confidence, and fix "Permission denied" errors including SELinux, with examples for RHEL and…
SQL Server Logins, Users and Permissions: A Least-Privilege Guide
Learn the difference between logins, users and roles, create a safe application account with only the permissions it needs, fix orphaned users and understand…



