Email security
SPF PermError: too many DNS lookups, and how to fix it
SPF allows 10 DNS lookups. Go over and SPF fails for all your mail. What counts, how to count yours, and five ways to get back under the limit.
By Brandon Sooknanan, Founder, Varaxon Technologies · · 5 min read
Every tool you sign up to wants a line in your SPF record. Add your mailbox provider, a newsletter platform, a CRM, a helpdesk and an invoicing system, and one day a checker says PermError: too many DNS lookups. Nothing looked broken, but from that moment SPF fails for every message you send.
This guide explains the limit, how to count your own lookups, and how to get back under it without breaking mail from the services you actually use.
What the 10-lookup limit is
When a mail server checks SPF, it reads your record and follows it, asking DNS more questions as it goes. To stop one record from making a receiving server do unlimited work, the SPF standard, RFC 7208, caps the questions at 10. Past that, evaluation stops with a permanent error, and SPF is treated as failing.
| Part of the record | Costs a lookup? | Notes |
|---|---|---|
include: | Yes, plus every lookup inside it | The most common cause. One include can hide three or four more. |
a | Yes | Looks up your domain's (or the named host's) address. |
mx | Yes | Looks up your MX records, then the address of each mail server. |
ptr | Yes | Slow and discouraged by the standard. Remove it. |
exists: | Yes | Rare outside large providers. |
redirect= | Yes | Hands evaluation to another domain's record. |
ip4: and ip6: | No | A fixed address or range. Free. |
all | No | The ending, such as -all or ~all. |
There's a second, smaller limit: lookups that find nothing, called void lookups. The standard recommends receivers fail SPF after two of them, so an include for a service that has shut down, or a typo in a domain name, can break SPF on its own.
How to count your lookups
The quick way: enter your domain in the SPF checker. It follows every include to the bottom, counts the lookups and the void lookups, and flags duplicate records. It reads public DNS only.
To count by hand, read your record with dig TXT yourdomain.com +short (on Windows, nslookup -type=txt yourdomain.com), then do the same for each include, and each include inside those. Here is an example record with five lookups at the top level:
v=spf1 include:spf.protection.outlook.com include:_spf.google.com include:servers.mcsv.net include:sendgrid.net mx ip4:203.0.113.10 -all
Four includes and an mx make five, and ip4 is free. But each include may contain more includes, so the real total is often double what you see. Providers change their own records too, which is how a domain that passed last year can fail today without anyone touching it.
Five ways to get back under 10
1. Remove services you no longer use
Most over-limit records carry at least one include for a tool the company stopped using years ago. If you're not sure whether a service still sends, look at your DMARC reports, which list every source sending as your domain. A service that hasn't appeared in a month of reports can usually go.
2. Move bulk senders to a subdomain
SPF is checked against the hidden bounce address (the Return-Path), not the From address people see. Most newsletter and transactional email services let you set a custom bounce domain, such as bounce.yourdomain.com or em.yourdomain.com. Once that's set up, their SPF check happens on the subdomain, and the include comes out of your main record. DMARC still passes, because a subdomain of yours aligns with your domain by default.
3. Replace a and mx with fixed addresses
If a or mx points at your own server with an address that doesn't change, replace it with ip4: (or ip6:) and that address. That saves a lookup each. Remove ptr outright.
4. Make sure each service signs with DKIM
DMARC only needs SPF or DKIM to pass and align. A service that signs your mail with a DKIM key for your domain keeps passing DMARC even when SPF doesn't cover it, which gives you room to tidy SPF without risk. Check which keys you publish with the DKIM checker.
5. Flatten, carefully
Flattening replaces includes with the IP ranges they currently resolve to, which costs no lookups. The catch: providers add and change addresses without telling you, and a flattened record goes stale silently. Only flatten with a service that re-checks and updates the record automatically, and never flatten your main mailbox provider's include by hand.
Other SPF mistakes worth checking
- Two SPF records. A domain may have only one TXT record starting
v=spf1. Two of them is a permanent error, and the checker flags it. Merge them into one. - A record over 255 characters. A single DNS text string can hold 255 characters. Longer records are split into several quoted strings that receivers join back together. Most DNS hosts do this for you, but a record pasted as one long string can be rejected or cut short.
- Ending in `+all` or `?all`. These tell receivers to trust everyone, or to ignore SPF. Use
~allwhile you finish checking senders, then-all.
What the error means for DMARC
A PermError counts as an SPF failure for DMARC. Mail that is also signed with an aligned DKIM key still passes DMARC, which is why some over-limit domains limp along without anyone noticing. Mail that relies on SPF alone fails, and once your DMARC policy is quarantine or reject, that mail goes to junk or is refused. Fix the count before you tighten DMARC. How to set up DMARC step by step covers the order.
Common questions
What does SPF PermError mean?
The SPF record can't be evaluated, usually because it needs more than 10 DNS lookups, makes too many lookups that find nothing, or the domain has two SPF records. Receivers treat it as an SPF failure.
Do ip4 and ip6 count toward the 10-lookup limit?
No. Fixed addresses and ranges need no DNS question, so they cost nothing. Only include, a, mx, ptr, exists and redirect count, along with every lookup inside an include.
Is SPF flattening safe?
Only when a service keeps the flattened record up to date. Providers change their sending addresses, and a hand-flattened record stops matching without warning.
Can I have two SPF records to get around the limit?
No. Two records starting v=spf1 on the same domain is itself a permanent error. Use one record, and move some senders to a subdomain with its own SPF record instead.
Turn your next scan export into a client-ready report.
Run a free pre-flight check