Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

SPF permerror: too many DNS lookups. Count the limit of 10, then shorten the record safely

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When mail from your domain shows an SPF result of permerror and a checker says there are too many DNS lookups, the record needs more DNS-querying terms than the standard allows. RFC 7208 says implementations "MUST limit the total number of those terms to 10 during SPF evaluation" and "If this limit is exceeded, the implementation MUST return "permerror"." The fix is to bring the count to 10 or fewer, not to add more records.

The wording about too many DNS lookups comes from checkers and receivers. The RFC defines only the result word permerror. Some receivers treat that as a failed check, so mail can be rejected, or handled by the receiver's local policy (RFC 7208 Appendix G.3), even though your sending servers are listed.

What the symptom means

SPF is a single line of text, published as a DNS TXT record, that lists who may send mail for a domain. A receiver reads it and evaluates the terms from left to right. RFC 7208 section 4.6.4 names the terms that cause DNS queries: the include, a, mx, ptr and exists mechanisms, and the redirect modifier. The terms all, ip4 and ip6, and the exp modifier, do not count.

The limit is one global count. Section 4.1 says the lookup limit "must be tracked as a single global limit for all evaluations, not just for a single instance of a recursive evaluation". An include that points at a provider's record counts once, and every counted term inside that provider's record counts as well, however deep the chain goes.

Three further rules matter:

  • An mx mechanism includes the number of MX records queried in the overall limit of 10, and each MX record must not lead to more than 10 address lookups; if that second limit is exceeded, the mechanism produces permerror.
  • Receivers SHOULD stop after more than two "void lookups", which are lookups that return no answer data or a name error. Exceeding that limit also produces permerror.
  • Mechanisms are evaluated left to right, and processing ends at the first match (section 4.6.2). The number of lookups a receiver performs can therefore depend on which sending address is being checked. A record can pass for one server and return permerror for another. RFC 7208 states the evaluation order and the limit, not a count per sending address.

A receiver records the result in the Authentication-Results header. RFC 8601 section 2.7.2 lists permerror among the values for the spf method, using the meaning in RFC 7208 section 2.6.7: the domain's published records could not be correctly interpreted, a condition that "definitely requires DNS operator intervention".

Likely causes

Cause What you see How to confirm
Several provider include terms (mail platform, CRM, helpdesk, newsletter tool) permerror after a new service was added Count each include, then count the counted terms inside each provider record
a, mx or ptr terms kept from an older setup Terms naming hosts that no longer send mail List each term and ask which sending system it covers
An mx term where the domain has many MX records Count higher than the number of terms you wrote Count MX records for the domain. RFC 7208 section 4.6.4: "the number of "MX" resource records queried is included in the overall limit of 10". Count both ways: the mx term once, and the term plus each MX record
More than two void lookups permerror with fewer than 10 terms An include, a or exists term names a host with no record
Two SPF records at the same name permerror with a short record More than one TXT record starting v=spf1 at that name (RFC 7208 section 4.5)
An include or redirect target with no SPF record permerror from that branch Query the target name and look for a v=spf1 string

Prove the cause before changing anything

All of these are read-only.

1. Read the published record.

dig +short TXT example.com

+short prints a terse answer, and the dig manual shows the form dig +short example.com. The TXT type is given as the query type. Write down every record that begins with v=spf1. Section 3.3 says several strings inside one TXT record are joined, so dig +short can show one record as several quoted strings. RFC 7208 section 4.5 says a result set with more than one such record produces permerror, so two records at one name is a separate fault from the lookup limit.

2. Read each provider record. For every include: and redirect= target, repeat the query with that name:

dig +short TXT mail.example.net

Keep going until every branch ends. A record with only ip4, ip6 and all terms ends the chain.

3. Count. Add one for each include, a, mx, ptr, exists and redirect across all the records you read. If you use mx, count it twice: once as a single term, and once with each MX record added (section 4.6.4 does not give a worked example). If both totals are 10 or fewer, the lookup limit is unlikely to be the cause. A total above 10 means the record can exceed the limit for some sending addresses, because evaluation stops at the first match (section 4.6.2). It does not by itself show that a receiver returned permerror. Step 4 confirms that: a receiver's spf=permerror result in Authentication-Results for a message from the sending system you are checking.

4. Check the receiver's view. In a delivered test message, find the Authentication-Results header. RFC 7208 section 9.2 and RFC 8601 show the form spf=pass followed by smtp.mailfrom=; a failing evaluation shows permerror in the result position.

Fix

Disruptive step: the SPF record is read by every receiver within the record's TTL. A wrong edit can cause legitimate mail to fail SPF everywhere. Before any change:

  1. Save the current value. Print it with the dig +short TXT command above and paste it into a dated note such as spf-example.com-2026-11-20.txt.
  2. Note the record's TTL as your DNS provider's console shows it.
  3. Make the change in the DNS provider's console in one edit, replacing the single v=spf1 string.

No configuration checker for a DNS record appears in the RFC or the dig manual, so the check is to query the name again and recount.

To back out: put the saved string back as the TXT value. Receivers that cached the new value keep it until the TTL expires.

Remove terms nobody needs

Risk: removing a provider that still sends mail turns its messages into SPF failures. To back out, put the saved record back.

Take out include, a, mx or ptr terms for systems that no longer send mail for the domain. Confirm with the owners of each service first.

RFC 7208 section 5.5 says the ptr mechanism "SHOULD NOT be published". Replace it with explicit ip4 or ip6 terms for the hosts it was covering.

Replace host terms with address ranges you control

Section 10.1.1 compares equivalent records for a domain with two mail hosts. Its first form, ip4:192.0.2.1 ip4:192.0.2.129 -all, needs no DNS lookups. The form mx:example.com -all, which the section labels the "Expensive record", needs them. Address terms cost no DNS lookup, so converting a and mx terms for servers whose addresses you control reduces the count.

Risk: an address written into the record does not follow the server if it is renumbered. Add a reminder to update the record whenever the address changes.

Provider terms that cannot be removed

For a provider you must keep, copying its address ranges into your own record is possible, but the RFC describes no method for this. Treat the following as advice, not a documented procedure:

  • The provider may change its ranges without telling you, so the copied list can go stale and valid mail can fail.
  • The record must stay small. RFC 7208 section 3.3 allows several strings of up to 255 octets in one TXT record, and section 3.4 recommends keeping the answer within 512 octets, which it translates to a combined length of the DNS name and the text of all the records of that type at the name (other TXT records there count too) of under 450 octets.
  • A different approach is to send each service from its own subdomain with its own short record, so that no single record carries every provider. Check each service's documentation to see whether it lets you set the envelope sender domain.

Risk: every one of these changes can break authentication for a service you did not know was using the domain. Make one change at a time and test after each.

Fix void lookups and broken targets

If a term names a host with no record, correct the name or remove the term. If an include target has no SPF record, section 5.2 states that the include returns permerror for a result of none. A redirect to a name with no SPF record also returns permerror (section 6.1).

Example (illustrative): example.com publishes v=spf1 mx a include:mail.example.net include:crm.example.org include:news.example.com ip4:203.0.113.10 -all. A receiver reports permerror. The record has five counted terms: mx, a and three include terms. The provider record at mail.example.net holds three include terms of its own (3 more). The record at crm.example.org holds a, mx and one include (3 more). The record at news.example.com holds one include (1 more). The total is 5 + 3 + 3 + 1 = 12, which is above 10, and the mx term could add more if the domain has several MX records. The administrator confirms the CRM is no longer used, removes include:crm.example.org (subtracting 1 + 3 = 4, giving 8), and replaces a and mx with ip4:203.0.113.20 after confirming that the one mail server uses that address (giving 6). The result is within the limit.

Confirm the fix

  1. Query the record again and recount using the same method. The total should be 10 or fewer.
  2. Confirm that only one TXT record at the name begins with v=spf1.
  3. Send a test message to a mailbox at a receiver that shows authentication results, and check that the spf result is no longer permerror.
  4. Test from each system that sends mail for the domain, not only the main mail server.

What to watch afterwards

  • Recount whenever you add a mail service. Each new include can bring several terms with it.
  • Keep a list of which service each term covers, so cleanups do not remove something still in use.
  • A provider that adds terms inside its own record can push your count over 10 without any change on your side. Recount after provider notices.
  • If you copied ranges into your record, schedule a check of them.

Risks and limits

  • These commands have not been run or lab-tested.
  • The RFC sets the limit for receivers. Some receivers implement it with their own wording or additional limits that differ from receiver to receiver.
  • The count of lookups depends on the evaluation path. The method here counts every term in the chain, which is the cautious reading.
  • The mx rule is described in the RFC with the wording that the number of MX records queried is "included in the overall limit of 10". Read your own record's MX count carefully, because the RFC does not give a worked example.
  • SPF alone does not decide delivery. DKIM, DMARC and reverse DNS are separate checks.

Sources