_noob.tools
My IP
All guides

SPF permerror: fixing the 'too many DNS lookups' limit

SPF allows only 10 DNS lookups. Learn what counts, how to see where you are, and how to get back under the limit without breaking your mail.

By noob.tools · · 4 min read

Mail that used to arrive starts landing in spam, and the headers say spf=permerror. A frequent cause is the SPF record itself: it is valid text, but evaluating it needs more than 10 DNS lookups, and receivers are required to stop there.

The rule

RFC 7208 limits an SPF evaluation to 10 mechanisms and modifiers that trigger a DNS query. If the count goes over, the result is permerror, which receivers treat as a failure: evaluation stops and no pass is recorded. A DMARC policy that depends on SPF then fails too.

What counts toward the 10:

  • include: (and everything the included record itself looks up)
  • a
  • mx (it counts once, and evaluating its hosts is separately capped at 10 address lookups)
  • ptr (also discouraged by the RFC)
  • exists:
  • the redirect= modifier

What does not count: ip4:, ip6: and all. They need no DNS query, which is why listing addresses directly is the cheapest way to spend the budget.

There is a second, less known limit: more than 2 void lookups (lookups that return nothing, such as a name that does not exist) also produces permerror. A stale include: for a service you stopped using is a typical source.

Why it creeps up on you

Every service that sends mail for you asks you to add its own include:. A company with a marketing platform, a ticketing system, a newsletter tool and Google Workspace or Microsoft 365 can reach 10 quickly, and the included records contain their own includes. You add the eighth service and nothing seems different, until the total tips over.

v=spf1 include:_spf.google.com include:sendgrid.net include:mailgun.org
       include:servers.mcsv.net include:spf.protection.outlook.com ~all

That looks like five lookups, but each of those records expands into more. The real total is what the receiver counts.

Check where you stand

Read the record and follow each include: by hand with a DNS lookup. The Advanced DNS Lookup tool can query TXT records for each included domain, and the Email Security Audit shows the SPF and DMARC records a domain publishes.

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

Count every mechanism from the list above across the whole tree. If you are at 10 or more, fix it before adding anything.

Try it yourselfEmail Security AuditAudit your domain's email hygiene.

Ways to get back under the limit

  1. Remove what you no longer use. Old services are the most common waste. Delete the include and any a or mx that is not needed.
  2. Replace a and mx with ip4: and ip6: when your own servers rarely change addresses. This turns lookups into free mechanisms.
  3. Move bulk senders to a subdomain. Send marketing mail from news.example.com with its own SPF record. Each domain gets its own 10-lookup budget, and your main domain stays clean.
  4. Flatten the record (replace includes with the IP ranges they resolve to). It works, but providers change their ranges, so a static flattened record silently goes stale and starts failing legitimate mail. Only do this with automation that re-flattens regularly, or for providers whose ranges you control.
  5. Use DKIM-aligned sending. DMARC passes if either SPF or DKIM passes and aligns. A sender that signs with your domain's DKIM does not strictly need to be in SPF, so you can drop it from the record if its mail passes via DKIM.

Writing the record

The DMARC & SPF Record Generator builds a record from your senders and shows the resulting text. After you publish the change, query the TXT record again to confirm that only one SPF record exists and that it ends with the policy you chose: ~all (soft fail) while you are still testing, -all (hard fail) when you are sure every legitimate sender is covered.

Checklist

  1. Count every include, a, mx, exists, ptr and redirect, including nested ones.
  2. Under 10 and no void lookups: you are fine.
  3. Over: remove unused services, then convert a/mx to ip4/ip6.
  4. Still over: split bulk senders onto a subdomain.
  5. Re-check the record after publishing, and confirm there is exactly one.

Tools used in this guide