Skip to content

SPF permerror: what 'too many DNS lookups' means and how to fix it

Your SPF record can break once it needs more than 10 DNS lookups. What counts toward the limit, why email fails, and how to count and cut lookups.

Ward Security Team

· 8 min read

Over the years, every service that sends email for your business asked you to add one line to your SPF record. The newsletter tool, the invoicing app, the CRM, the booking page. Nobody counted the lines.

Then quotes start landing in spam, or a customer says your invoice never came. Nothing changed last week. The record just crossed a limit that most people have never heard of.

An example SPF record counted term by term. The 11th lookup breaks it. Names are invented, and the lookups inside each include are included in the count.

What does "SPF permerror: too many DNS lookups" mean?

It means your SPF record needs more than 10 DNS lookups to be checked, so the receiving server gives up and reports a permanent error. SPF (Sender Policy Framework) is the public list of servers allowed to send email as your domain. A DNS lookup is one question to the internet's public address book.

To check a message, the receiving server reads your list and follows every reference in it. RFC 7208, the SPF standard, says implementations must limit those terms to 10 per evaluation. Above that, the result is "permerror". The RFC defines a permerror as a result meaning the domain's published records could not be correctly interpreted.

The standard sets the limit to keep the load on DNS reasonable.

What counts toward the 10-lookup limit?

Each include, a, mx, ptr and exists mechanism counts, and so does the redirect modifier. These are the terms that cause DNS queries at evaluation time, according to RFC 7208 section 4.6.4. The ip4, ip6 and all mechanisms and the exp modifier cost nothing.

Which SPF terms use one of the 10 lookups, according to RFC 7208 section 4.6.4.

The trap is nesting. When you write "include:send.example", the server reads that service's own record, and every include inside it counts too. Microsoft puts it plainly in its SPF guide: having fewer than 10 include statements doesn't guarantee fewer than 10 lookups.

Two smaller rules are worth knowing:

  • Void lookups. A lookup that returns nothing, such as an include pointing at a domain that no longer exists, is called void. The RFC says implementations should stop at two void lookups, and exceeding the limit is a permerror too.
  • Redirect. A redirect only applies when the record has no "all" at the end. If both are present, the redirect is ignored.

Why does it make legitimate email fail or go to spam?

Because a permerror means SPF can no longer confirm that your server was allowed to send. Your message is treated as unverified, which is the same starting point a forged message has.

What the receiver does next is its own decision. The standard defines the result, not the consequence. Some services deliver the message and mark it, some send it to spam, and some bounce it. Microsoft documents that a receiving system can reject the message with a bounce that says "The message required too many lookups".

DMARC, the policy that sits on top of SPF and DKIM, passes when either one passes and matches your From address. So a message that carries a valid DKIM signature for your domain can still pass DMARC while SPF is broken. Mail from services that don't sign with your domain has nothing to fall back on. If you are not sure where DMARC stands, start with can someone send email from my domain.

A broken SPF can be one of the causes behind the problems in why your emails go to spam.

How do I count my SPF lookups?

Read your record, then read the record of every include inside it, and count each term from the list above. Five minutes with a DNS lookup tool is enough for a small business.

  1. Get your record. Look up the TXT record of yourcompany.com and find the one that starts with "v=spf1". Online DNS lookup tools show it, or you can run dig +short TXT yourcompany.com in a terminal.
  2. Count the direct terms. Add one for each include, a, mx, ptr and exists, and one for a redirect. Ignore ip4, ip6 and all.
  3. Open every include. Look up the TXT record of each included domain and repeat step 2 inside it. Then open the includes you find there.
  4. Add it up. If the total is 10 or less, you are inside the limit. If it is 11 or more, SPF is broken for every receiver that follows the standard.

Do this again whenever you add a service. The number only goes up.

How do I reduce the number of lookups?

Start with the easy cuts and go further only if you still need to. Most small businesses fix this with the first step.

1. Remove includes for services you no longer use

Every dead service you left in the record spends a lookup and still lets that service send email as you. Old newsletter tools, a previous mailbox provider and former CRMs are the usual leftovers.

Before you delete a line, check with your team that nobody uses the service, even occasionally. A yearly campaign or an occasional invoicing tool can go months without sending. Your DMARC reports also show who really sends as your domain, and they are the safest way to decide.

2. Give busy senders their own subdomain

Move a service that sends a lot to a subdomain such as news.yourcompany.com, and publish a separate SPF record there. SPF is checked against the technical sender address of each message, not always the one you see in the "From" line, and a subdomain does not inherit the record of the main domain. So each domain gets its own budget of 10.

One record for everythingyourcompany.com14 lookupsSPF error(permerror)One record per senderyourcompany.com4 lookupsnews.yourcompany.com6 lookupspay.yourcompany.com4 lookupsEach domain is checked on its own. Example numbers.
One record for everything breaks the limit. One record per sender keeps each domain within it. Example numbers.

This only works if the service lets you set the domain it uses as the technical sender, and many do. Check its help pages before you plan around it. Keep DKIM signing on for every service, so DMARC still has something to pass.

3. Ask each service for a lighter entry

Some providers may offer a lighter SPF entry than the one you copied years ago. Ask each service that is still in your record.

4. Flatten only as a last resort

Flattening replaces an include with the fixed IP addresses behind it, written as "ip4:" and "ip6:" entries. Those cost zero lookups, which is why it works.

The risk is that the addresses change and your copy does not. Microsoft warns against flattening its own include because its sending infrastructure uses dynamic IP addresses that change frequently. If a provider adds a server you did not copy, your real email fails SPF. Flatten only a service that publishes stable addresses, and write down the date so someone rechecks it.

Never "fix" the limit by publishing a second SPF record. Two SPF records on one domain are also a permerror.

How does Ward detect this?

Ward reads your public SPF record from outside, follows every include and redirect the way a receiving server would, and counts the lookups. If the total goes over 10, it reports the finding below. It reads public DNS only and changes nothing.

Example Ward finding for yourcompany.com, with the wording Ward uses for this check. Domain, record and count are examples.

Ward counts the same terms as the standard: include, a, mx, ptr, exists and redirect, nested ones included. It also flags related SPF problems separately. An include that points to a domain with no SPF record, a record with formatting errors, two records on one domain and the discouraged "ptr" mechanism each get their own finding.

If you receive your DMARC reports with Ward, it can also tell you which includes haven't sent anything in the last 60 days, which is the shortlist for step 1. The details of each finding are in the email check guide.

What should I do this week?

  • Count your lookups, by hand or with a free scan.
  • List every service in your SPF and mark the ones you still use.
  • Remove the dead ones, then recount.
  • If you are still over, move your busiest sender to a subdomain.
  • Send a test message to a personal Gmail or Outlook account and check that SPF passes.

Once SPF is healthy, the next step is making DMARC enforce it. The DMARC setup guide walks through it. A fake invoice is the most common way a weak setup costs money, and the fake invoice scam shows how to stop it.

In Ward's guide

What Ward checks for this, with the steps to fix it:

Frequently asked questions

What does SPF permerror mean?
It means the receiving server could not correctly interpret your SPF record. Going over 10 DNS lookups is one cause. Two SPF records, a syntax error or an include that points nowhere are others.
Does the 10-lookup limit count every include?
Yes, and it also counts the includes nested inside the lists of the services you include. The terms include, a, mx, ptr, exists and the redirect modifier each use one lookup. ip4, ip6 and all use none.
Will my emails go to spam if my SPF has too many lookups?
They can. Your SPF returns an error instead of a pass, and each receiving service decides what to do with that. Messages that carry a valid DKIM signature for your domain can still pass DMARC.
How do I check how many lookups my SPF uses?
Read your SPF TXT record, then read the record of every include inside it, and keep going until there are no more. Count each include, a, mx, ptr, exists and redirect. A free scan from Ward does the count for you.
Is SPF flattening a good fix?
Only as a last resort. Flattening swaps includes for fixed IP addresses, and big providers change their addresses without notice. A stale list makes your real email fail SPF.
Can I use more than one SPF record to get around the limit?
No. Two SPF records on the same domain also produce a permerror. Split senders across subdomains instead, with one SPF record on each.

Sources

  1. RFC 7208: Sender Policy Framework (SPF), section 4.6.4 DNS lookup limits
  2. Microsoft Learn: Set up SPF to help prevent spoofing
Written by Ward Security Team. We build Ward, a passive external security check for small businesses: it looks at your company from the outside, the way an attacker would, and tells you what to fix first.