SPF too many DNS lookups: fixing the 10-lookup limit

SPF allows at most 10 DNS lookups per evaluation. The include, a, mx, ptr and exists mechanisms and the redirect modifier each count, including those inside included records. Going over returns a permanent error (permerror) and SPF fails. Fix it by removing unused includes, replacing includes with ip4 ranges, or consolidating senders.

Why the limit exists

To check SPF, the receiving server has to run DNS queries while the sender waits. Without a cap, a malicious or badly written record could trigger a very large number of queries. RFC 7208 therefore limits evaluation to 10 DNS-querying terms. When the count passes 10 the result is permerror, a permanent error, and receivers generally treat the message as failing SPF.

What counts and what does not

Only terms that cause DNS queries count, and the count includes the records you include, recursively.

  • Count: include, a, mx, ptr, exists, and the redirect modifier
  • Do not count: ip4, ip6 and all
  • Each include that itself contains includes adds all of those too
  • The mx mechanism also needs address lookups for the mail hosts, which have their own limit
  • Many lookups that return nothing (void lookups) can also cause an error; the standard suggests limiting them to two
v=spf1 include:_spf.google.com include:servers.mcsv.net include:sendgrid.net include:spf.protection.outlook.com ~all

How to count your lookups

Look up your SPF record and note each include, a, mx, exists and redirect. Then look up each included domain's record and repeat. The sum is your total. In the example above, four includes already use at least four lookups, and big providers' records often contain several includes of their own, so it is easy to reach 10 with a handful of services.

DomainGuard counts the lookup-causing terms written directly in your record and warns when you are close to the limit or over it. It does not expand nested includes, so the real total can be higher than the count it shows; treat its figure as a minimum.

Ways to get under the limit

Start by removing includes for services you no longer use, which is the most common cause. Then replace an include with ip4 ranges only when the provider publishes stable addresses, because their addresses can change and a hard-coded range will go out of date. Move bulk or marketing mail to a subdomain, for example mail.example.com, with its own SPF record so each domain has its own budget of 10.

SPF flattening services rewrite includes into ip4 lists automatically, but they must keep the record updated or it silently breaks. Whichever route you take, never publish two SPF records to split the load: that is itself a permerror.

How DomainGuard helps

Scheduled scans on paid plans re-read your record and alert you when it changes, which is when an extra include usually slips in. The checker is read-only: you make the DNS edit yourself.

Frequently asked questions

What is SPF permerror?

A permanent error in SPF evaluation, caused by problems such as multiple SPF records, bad syntax or more than 10 DNS lookups. Receivers generally treat it as an SPF failure.

Does ip4 count toward the 10 lookups?

No. ip4, ip6 and all do not cause DNS queries, so they are free. Include, a, mx, ptr, exists and redirect do count.

Can I split my SPF record into two?

No. A domain must publish exactly one SPF record. Use a subdomain for some senders instead.

Is it safe to flatten SPF myself?

Only if you keep it updated. Providers change their IP ranges, and an out-of-date flattened record can make real mail fail.