Under RFC 7208, which SPF terms count toward the 10-DNS-lookup limit, and which terms cost nothing?
answer
- terms that query DNS mid-check
- one budget across the whole tree
- a modifier counts too
- address literals are free
- eleventh term: permerror
basics
~20 sRFC 7208 counts include, a, mx, ptr, exists and the redirect modifier toward one limit of ten, shared by every nested include; going past ten gives permerror. The ip4, ip6 and all mechanisms and the exp modifier cost nothing.
solid answer
~40 sSection 4.6.4 of RFC 7208 names the terms that make a receiver query DNS during the check: the `include`, `a`, `mx`, `ptr` and `exists` mechanisms and the `redirect=` modifier. Implementations MUST cap those at 10 and MUST return `permerror` when the cap is exceeded. It is one global budget for the whole evaluation, so every term inside an included record spends from the same ten as your top-level record. `ip4`, `ip6` and `all` need no query, and `exp=` is fetched only afterwards to explain a fail, so none of them count. On top of the ten, each `mx` or `ptr` term may go on to query at most 10 A or AAAA records: past that, `mx` gives `permerror` and `ptr` ignores everything after the first ten.
go deeper
Remember the six terms that cost a lookup: include, a, mx, ptr, exists and redirect. The ip4, ip6 and all mechanisms and the exp modifier do not.
Explain that the ten is one global budget for the whole check, so nested includes spend from it, and that mx and ptr carry their own limit of ten address queries.
Show you can tell a hosted service's include is an unknown cost until resolved, and that its nested terms land in your own count without any change to your zone.
Frame the limit as a design constraint on how many outside services may send as the main domain, not as a syntax rule to work around.
## Why SPF budgets DNS at all **SPF** (Sender Policy Framework, RFC 7208, April 2014) lets a domain owner publish, in a DNS TXT record beginning `v=spf1`, which hosts may use the domain in the SMTP `MAIL FROM` (or `HELO`) identity. A receiver checks the connecting IP address against that record. Many terms in the record do not contain addresses at all; they tell the receiver to go and **look something up**. Every lookup is work done by the receiver, on behalf of whoever wrote the record, for every message that claims the domain. Section 11.1 of RFC 7208 explains the danger: a short SMTP transaction can make each verifier it reaches issue many DNS queries, possibly into a third party's zone, so SPF verifiers could be used to **amplify** traffic. A limit that sounds generous for one mail server still multiplies across thousands of receivers, so the RFC sets the limits "quite low". ## The terms that spend a lookup Section 4.6.4 divides the terms (mechanisms and modifiers together) into two groups: | Term | Kind | Counts toward 10? | Why | |---|---|---|---| | `include:` | mechanism | yes | fetches and evaluates another domain's SPF record | | `a` | mechanism | yes | queries A or AAAA for a name | | `mx` | mechanism | yes | queries MX, then the addresses of each MX host | | `ptr` | mechanism | yes | reverse-maps the client IP, then confirms names | | `exists:` | mechanism | yes | queries an A record for a constructed name | | `redirect=` | modifier | yes | replaces the check with another domain's record | | `ip4:` / `ip6:` | mechanism | no | the address is in the record itself | | `all` | mechanism | no | always matches; no data needed | | `exp=` | modifier | no | fetched only later, to explain a fail | The wording is a **MUST**: implementations MUST limit the total of the counted terms to 10 during evaluation, and if the limit is exceeded they MUST return `permerror`, the result RFC 7208 defines as "the domain's published records could not be correctly interpreted" and that needs the DNS operator to fix it. ## One budget for the whole tree The single most misunderstood point is scope. Section 4.1 says the overall lookup limit "must be tracked as a single global limit for all evaluations, not just for a single instance of a recursive evaluation". In practice: - An `include:` costs one lookup itself, and **every counted term inside the included record** costs one more from the same ten. - That applies recursively: an include inside an include inside an include all draw on one budget. - A `redirect=` target's counted terms also spend from the same budget. - A hosted sending service's own record is therefore part of **your** count, and it can change without anyone editing your zone. - The fetch of your own top-level record is not a term and is not counted. ## The per-term sublimits for mx and ptr Two mechanisms can fan out into many address queries, so RFC 7208 adds a second limit that applies **per term**, in addition to the ten: 1. Each `mx` term costs one of the ten, and resolving its MX hosts MUST NOT query more than 10 A or AAAA records; past that, the `mx` mechanism MUST produce `permerror`. 2. Each `ptr` term (and the `%{p}` macro) is bounded the same way, but past ten names the rest MUST be ignored rather than producing an error. The RFC explains the difference: a domain controls its own MX set, so an oversized one is the publisher's error, while the PTR records belong to whoever owns the connecting address. ## Void lookups and time, briefly Two related limits sit in the same section. Queries that come back with NXDOMAIN or an empty answer are **void lookups**, and implementations SHOULD stop at two, returning `permerror` beyond that. A verifier SHOULD also cap total evaluation time at no less than 20 seconds, and exceeding it SHOULD give `temperror`. Both are separate from the count of ten. ## What this means for the record you publish - Prefer `ip4:` and `ip6:` for addresses you control; RFC 7208 section 10.1.2 says to use them over `a`, and `a` over `mx`, unless your hosts change often. - Treat every `include:` as an unknown cost until you have resolved the record behind it. - Re-count whenever a sender is added, since one new service can carry several nested lookups. - Leave `ptr` out entirely: RFC 7208 says it SHOULD NOT be published, and it spends a lookup besides. What a `permerror` then does to delivery, and how DMARC treats it, belongs to the material on SPF results; this question stops at which terms spend the budget.
- Why does RFC 7208 set the cap so low when ten queries cost one receiver almost nothing?Because the cost is multiplied. Section 11.1 describes SPF verifiers being used to amplify DNS traffic: one short SMTP transaction makes every receiver it reaches query names the record's author chose, possibly in someone else's zone. Limits reasonable for a single server still allow large amplification across many receivers, so the RFC keeps them low.
- Does the redirect= modifier spend a lookup even though it is not a mechanism?Yes. Section 4.6.4 lists `redirect` explicitly beside the five mechanisms. It is acted on only when no mechanism matched and is ignored when the record contains `all`, but when it is followed, it costs one lookup and the target record's counted terms spend from the same budget of ten.
- Is the limit counted in DNS queries or in terms?In terms. An `mx` term counts once even though it queries MX and then several addresses; those address queries fall under its own sublimit of ten instead. An `include:` counts once for fetching the target record, and each counted term inside that record then counts on its own.
- ip4 and ip6 entries count toward the ten because they are DNS data.
- Each included vendor record gets its own fresh budget of ten lookups.
- The all mechanism costs a lookup because it ends the evaluation.
- Going over ten lookups gives softfail, so most mail still arrives.
- An mx term costs one lookup per MX host it returns.
- The redirect modifier is free because only mechanisms are counted.