← All posts

How to fix SPF PermError: too many DNS lookups

SPFTroubleshooting

SPF has a hard limit: evaluating a record may trigger at most 10 DNS lookups. Go over it and receivers return permerror, which means your SPF check fails no matter who is sending.

What counts as a lookup

These mechanisms each cost one lookup, plus whatever lookups happen inside them:

  • include:
  • a
  • mx (and each MX host’s address can add more)
  • ptr (avoid it entirely)
  • exists:
  • the redirect= modifier

These cost nothing: ip4:, ip6: and all.

Nested includes count too. include:_spf.google.com for example, expands to further includes, which is why a record with only five visible include: entries can still exceed ten.

There is also a limit of two void lookups: lookups that return no data. Dead includes for services you no longer use can trigger it.

Count yours

Follow each include: by hand:

dig +short TXT example.com
dig +short TXT _spf.google.com

Or paste your domain into a checker that expands the whole tree and shows the total.

How to get under 10

  1. Delete services you no longer use. Old newsletter tools and trials are the usual culprits.
  2. Replace a and mx with ip4:/ip6: if the addresses are stable and you control them.
  3. Move services to subdomains. Send marketing mail from news.example.com with its own SPF record, so the root record stays small. Each (sub)domain gets its own 10-lookup budget.
  4. Flatten with care. Replacing an include: with the provider’s current IP list removes lookups, but those IPs change. If you flatten by hand the record goes stale and legitimate mail starts failing. Only do it with a tool that keeps the record updated automatically.
  5. Remove ptr. It is deprecated and slow.

What not to do

Do not publish two SPF records to “split” the lookups. Two records are an error on their own, and the result is again permerror.

Verify

After the change, re-count the lookups, then send a test message and check for spf=pass. See how to read email headers and, for the basics, SPF, DKIM and DMARC explained.