Skip to content
  • There are no suggestions because the search field is empty.

SPF permerror: too many DNS lookups

An SPF "too many DNS lookups" error means a receiver had to make more than 10 DNS lookups while checking your SPF record, so it stopped and returned a permanent error (permerror). That check can't produce an SPF pass. The record still exists; the receiver just couldn't finish evaluating it. The fix is to cut the number of lookup-causing terms, starting with includes for services you no longer use. Mail that carries an aligned DKIM signature can still pass DMARC while you fix it.

What the limit is and what permerror means in general are covered in The 10-lookup limit and SPF permerror. This article is the hands-on part: how to count, where the lookups hide, and what to remove first.

Why SPF says "too many DNS lookups"

A single SPF check may trigger at most 10 DNS-querying terms. If the limit is exceeded, the result is permerror.

Costs one lookup Costs nothing
include, a, mx, ptr, exists, and the redirect modifier ip4, ip6, all, exp

The trap is nesting. Every lookup inside an included record counts toward your 10 as well. Nested lookups count toward the limit of 10 DNS lookups, so a record with four includes can easily cost 12.

Two smaller limits can also give permerror: a single mx term that needs more than 10 address lookups, and more than two "void" lookups (names that don't exist or return nothing). The void-lookup cap is a SHOULD, so not every receiver enforces it, but a deleted vendor hostname left in your record is one way to hit it.

Why only some mail breaks

Evaluation stops at the first match. Mail from an ip4: range near the front of your record can pass before the receiver ever reaches the includes that push the count over 10, while mail from a vendor whose include sits at the end gets permerror from the same record. A record over the limit can still pass for some streams. Don't treat that as a reason to leave it: which stream breaks depends on where its match sits in the record, and that changes whenever you or a vendor edit an include. Keep the whole record, fully expanded, at 10 or fewer.

How to count your lookups

You can do this by hand with any DNS lookup tool (or dig TXT on the command line).

  1. Look up the TXT record at the domain your mail uses as its envelope sender (the Return-Path domain, which is what SPF checks).
  2. Count every include, a, mx, ptr, exists, and redirect in it.
  3. For each include and redirect, look up the record it points to and count its terms the same way.
  4. Keep going until you reach records with only ip4, ip6, and all.

A worked example for example.com:

v=spf1 mx include:_spf.mailhost.example include:spf.crm-vendor.example include:mail.newsletter.example include:send.old-survey-tool.example ~all
Term What's inside Lookups
mx — 1
include:_spf.mailhost.example 3 more includes 4
include:spf.crm-vendor.example 2 more includes 3
include:mail.newsletter.example 1 more include 2
include:send.old-survey-tool.example only ip4 1
~all — 0
Total 11

Eleven: permerror for any message whose check gets that far. Nobody added an eleventh term on purpose. One vendor added a nested include on its side, and the record went over.

Counts can change without you touching DNS, because vendors edit their own records. Microsoft also notes that the number of lookups "can be different than the number of DNS queries" a resolver sends, so count terms, not packets.

What the error looks like

  • In message headers: spf=permerror in Authentication-Results.
  • In bounces: a receiving system can reject the message with a non-delivery report containing "The message exceeded the hop count." or "The message required too many lookups." The enhanced status code 5.7.24 means an SPF validation error, but receivers choose their own codes and text.
  • In DMARC aggregate reports: a permerror SPF result on sources that should be passing (A field-by-field walk-through of a DMARC aggregate report).

What a receiver does with permerror is its own policy. Some reject, some deliver and simply treat SPF as not passing. Don't assume one outcome.

How to fix too many DNS lookups

Work through these in order. Each step is safer than the one after it.

  1. Confirm what still sends. Before you delete anything, check your DMARC aggregate reports and ask the owners of each service. Removing an include for a tool that's still in use trades one failure for another (How to inventory sending sources).
  2. Remove includes for services that no longer send. Google's advice is to "remove any include mechanisms for third parties that no longer send mail for your domain." In the example above, the old survey tool goes first.
  3. Remove includes that don't help. SPF is checked against the envelope (Return-Path) domain, not your From address. If a vendor sends with its own bounce domain, receivers never consult your SPF record for that mail, so its include costs lookups and does nothing for DMARC. Check the Return-Path in a real message from that vendor before you remove it (SPF include vs DKIM from the vendor).
  4. Drop ptr. Don't publish this mechanism. It's slow, and it costs a lookup.
  5. Replace a and mx with ip4/ip6 for servers you run yourself on fixed addresses. The IP mechanisms cost nothing.
  6. Move a sending stream to its own subdomain. If a platform sends with an envelope domain like bounce.news.example.com, that name has its own SPF record and its own budget of 10. Under relaxed alignment it still aligns with a From address at example.com (Identifier alignment for SPF and DKIM, How to add a third-party sender without breaking DMARC).
  7. Flatten only as a last resort. Replacing an include with the IPs it resolves to removes lookups, but the IPs go stale when the vendor changes them, and the SPF standard doesn't require flattening. The trade-offs, and why not to flatten Microsoft 365, are in The 10-lookup limit and SPF permerror.
  8. Recount after every change, then wait. Fixes can take 24 to 48 hours to take effect because of DNS caching.

What doesn't fix it

  • Splitting the record into a second SPF record. Two v=spf1 records at the same name give their own permerror (Two SPF records).
  • Changing ~all to -all, or back. The qualifier on all doesn't change the lookup count.
  • Adding more includes to "cover" failing senders. Each one adds to the count.

Don't let SPF carry DMARC alone

DMARC passes when either SPF or DKIM passes for a domain aligned with the From address. While SPF is in permerror, aligned DKIM is what keeps your mail passing. If a sender can sign with your domain, its mail doesn't need its include in your record to pass DMARC at all (SPF include vs DKIM from the vendor).

That matters more as you move toward enforcement. Domains that publish p=reject must not rely solely on SPF to secure a DMARC pass and must apply valid DKIM signatures to their messages (When you are ready for p=reject).

Mistakes worth avoiding

  • Counting only the top-level includes and missing the nested ones.
  • Keeping includes for retired tools "just in case."
  • Adding a vendor's include when the vendor bounces to its own domain.
  • Flattening once and never updating it.
  • Fixing SPF but never turning on DKIM, then moving to p=reject.

More SPF slips are in Common SPF mistakes, and what each mechanism does is in SPF mechanisms: include, a, mx, ip4, ip6, redirect.

Free DMARC account

Not sure which sender is failing?

Connect your domain's DMARC reports and see every service that sends as your domain, and whether each one passes SPF, DKIM and DMARC.

  • Every sending source in one dashboard
  • SPF, DKIM and alignment results per sender
  • No XML files to read

Create a free DMARC accountTalk to an expert

FAQ

Does ip4: count toward the 10 lookups?

No. Only include, a, mx, ptr, exists, and redirect do, including the ones inside your includes.

Does redirect= count?

Yes, one lookup, plus whatever is in the record it points to.

Will my mail bounce?

It depends on the receiver. Some reject, and Microsoft documents NDRs for it. Others deliver and treat SPF as not passing. DMARC can still pass if DKIM passes with alignment.

Can I fix it by adding a second SPF record?

No. Two SPF records at the same name are their own permerror (Two SPF records).

Should I flatten my SPF record?

Only after removing unused includes, and only for vendors whose IPs you can keep up to date. See The 10-lookup limit and SPF permerror.

How long until the fix works?

It depends on DNS caching. 24 to 48 hours.