SPF PermError: too many DNS lookups, and how to get under 10
SPF (Sender Policy Framework) records authenticate mail senders by listing authorized IP addresses and mail servers. However, SPF has a hard limit: each DNS query during SPF validation counts toward a maximum of 10 lookups per check. Exceed that limit and receivers return a PermError (permanent error), causing legitimate mail to be rejected or deferred. This article explains the limit, identifies common causes, and shows you how to optimize your SPF record to stay under 10.
Understanding the SPF 10-Lookup Limit
RFC 7208 defines the SPF mechanism evaluation process. Each mechanism that requires a DNS query counts against the limit. A "lookup" occurs when the receiver's mail server performs a DNS query to evaluate an SPF mechanism—for example, looking up an A record, MX record, or following an include. When the receiver reaches 10 lookups, further mechanisms are not evaluated, and the result is PermError.
This limit exists to prevent denial-of-service attacks and reduce resolver load. It applies globally: all mechanisms in your SPF record, plus all nested includes, count toward the same pool. A single poorly designed SPF chain can waste lookups and cause legitimate mail to fail.
Common Causes of SPF Lookup Bloat
- →Too many include mechanisms: each include statement counts as one lookup, plus any lookups needed to evaluate the included record.
- →Nested includes: including a record that itself includes other records multiplies lookups quickly.
- →Multiple A and MX mechanisms: each A or MX mechanism requires a DNS query for every domain listed.
- →Unused or legacy mechanisms: old mail server references or third-party services still in the record but no longer used.
- →Overly broad MX mechanisms: including MX records when you only need specific mail servers.
Strategies to Reduce DNS Lookups
Audit your current SPF record first. Use an SPF checker or analyzer to see which mechanisms are consuming lookups. Then apply these techniques:
- →Consolidate includes: combine multiple third-party services into a single include where possible, or choose providers that offer consolidated SPF includes.
- →Use IP ranges instead of includes: if you control both domains, publish CIDR ranges directly in your main SPF record rather than including another domain.
- →Remove redundant mechanisms: if your A record is already included via an MX mechanism, remove the explicit A mechanism.
- →Eliminate unused mechanisms: delete references to old mail servers, acquired companies, or deprecated services.
- →Flatten nested includes: ask third-party providers if they offer a flattened SPF record or consolidated IP list you can publish directly.
- →Use ptr sparingly: the ptr mechanism is deprecated and counts as multiple lookups; avoid it entirely.
Example: Before and After
A typical bloated SPF record might look like this:
v=spf1 include:_spf.google.com include:sendgrid.net include:servers.mcsv.net include:mail.zendesk.com a mx ptr ~all
This record uses at least 6 lookups: one for each include, plus one for A, one for MX, and one for ptr. If any included record itself contains includes, the total climbs higher and may exceed 10.
An optimized version consolidates and removes redundancy:
v=spf1 include:_spf.google.com ip4:192.0.2.0/24 ip4:198.51.100.0/24 a -all
This uses only 3 lookups: one for the Google include, one for the A record, and two IP ranges that require no lookup. The ptr mechanism is removed, and the MX mechanism is dropped because the A record covers the mail server. The result is faster, more reliable delivery and room for future additions.
Validation and Testing
After optimizing, validate your SPF record with a live DNS lookup tool or SPF checker. Confirm that your mail servers still pass SPF validation and that no legitimate senders are rejected. Monitor your mail logs for SPF PermError results over the next week to catch any issues.