skip to content

A vendor offers to flatten your SPF record's includes into ip4 and ip6 ranges to get under ten lookups; how do you decide whether to accept?

level: principalimportance: should knowfreq 20%

answer

  1. trade the cap for drift
  2. whose addresses, whose schedule
  3. prune before you flatten
  4. automation needs an owner
  5. a subdomain per sender

basics

~20 s

Flattening trades the lookup cap for drift: the copied ranges go stale when a service changes addresses, and that mail then fails SPF silently. Prune first; flatten only with automated re-resolution and alerting, or move a sender to its own subdomain.

solid answer

~50 s

Flattening replaces `include:` terms with the `ip4:` and `ip6:` ranges those includes currently resolve to, so the record costs few or no lookups. The price is **drift**: the ranges belong to the service, which changes them on its own schedule, and every change it makes is invisible to your copy until someone refreshes it, so new sending addresses fail SPF quietly. I start with the cheaper moves: remove includes for services no longer used, replace `a` and `mx` for our own fixed hosts with literals, and ask whether each service must send as the main domain at all, or can use its own envelope subdomain. If the count is still over ten, I accept flattening only for services with stable, published ranges, and only with an owner, a scheduled re-resolution of the original includes, and an alert on any difference.

go deeper

for a junior

Recall what flattening means: replacing includes with the ip4 and ip6 ranges they resolve to, which costs no lookups but goes stale.

for a middle

Explain why literals do not count toward the ten, and what drift is: the service changes its ranges and your copy does not follow.

for a senior

Show the cheaper moves you would make first, and the automation, alerting and ownership a flattened record needs to stay correct.

for a principal

Own the trade: a loud permerror against a quiet partial failure, and whether the real fix is a rule on which services may send as the main domain.

## What flattening does An SPF record (RFC 7208) lists who may send with a domain in the `MAIL FROM` identity. Hosted sending services are usually authorised with an `include:` term that points at the service's own record. Each include, and every counted term nested inside it, spends from the **limit of ten DNS-querying terms** in section 4.6.4, and the eleventh gives `permerror`. **Flattening** is an operational technique, not an RFC term: you resolve each include today, collect the `ip4:` and `ip6:` ranges it ends in, and publish those literals in your own record instead. Address literals need no query and do not count, so a record that needed fourteen lookups can need two. RFC 7208 itself points both ways. Section 10.1.1 shows a record of plain `ip4:` terms as the "best" for DNS cost, and section 10.1.2 adds that `a` or `mx` let hosts be renumbered easily "at the cost of a DNS query per receiver", so literals are better "unless such changes are common". Flattening is that trade applied to addresses you do not control. ## The drift it creates The include was a live reference; the flattened copy is a snapshot. Drift is every way the two diverge: - The service **adds** sending addresses. Mail from them no longer matches your record and falls to the record's `all` term, typically `fail` or `softfail`. Nothing errors; mail just starts failing for some messages. - The service **retires** addresses. Your record keeps authorising ranges the service may hand to someone else. - The service **restructures** its nested records. A refresh tool that followed the old structure may miss part of the new one. - Your record **grows**. Long lists of literals push against the record-size guidance covered with SPF record syntax, and may need splitting into further strings. The failure mode is the reason flattening is a lead's decision: it removes a loud, immediate error (`permerror`) and replaces it with a quiet, partial one that surfaces only when someone looks at results per sender. ## Cheaper moves first Before flattening anything, the usual sequence is: 1. **Prune.** Remove includes for services no longer used; an audit of a long-lived record often recovers several lookups and removes names that might become void lookups. 2. **Use literals for your own hosts.** Replace `a` and `mx` for your own fixed outbound servers with `ip4:` and `ip6:`, as section 10.1.2 recommends; you control those addresses and know when they change. 3. **Consolidate your own hosts behind one name.** Section 10.1.1's "good" record uses a single `a:` name in your own zone carrying several address records: one lookup for many hosts, and renumbering stays a zone edit. 4. **Ask which services must send as the main domain at all.** A service that can use its own envelope subdomain, with a small record of its own, stops spending the main record's budget. 5. **Flatten selectively**, only the includes whose services publish stable ranges and announce changes. ## If you do flatten: running it Flattening is a small production system, and it needs what any production system needs: - **An owner.** A named team that is paged when the refresh fails, not whoever set it up. - **The include list as the source of truth.** Keep the original includes in configuration, resolve them on a schedule, and generate the published literals from them. - **Diff alerts.** Alert when the resolved ranges change, and review before publishing rather than overwriting blindly. - **Short refresh cycles and a sane TTL**, so a corrected record reaches receivers quickly. - **Monitoring of SPF results per sender**, so drift shows up as a falling pass rate for one service rather than as a complaint weeks later. - **A contract term or notice channel** with each service for address changes, where one exists. ## Weighing the options | Option | Lookups saved | Drift risk | Ongoing cost | |---|---|---|---| | Prune retired services | some | none | an offboarding step | | Literals for your own hosts | one per term | low, you control the addresses | edit on renumbering | | One `a:` name for your own hosts | several | low | zone edits | | Sender on its own envelope subdomain | that sender's whole tree | none for the main record | a record per subdomain | | Flatten a service's include | that include's whole tree | high, the service controls the addresses | automation, alerts, an owner | There is no single right answer. A company with two stable services and one oversized include may flatten that one include and be done. A company adding a service every quarter is better served by a rule about which services may send as the main domain at all, because flattening only postpones the next count over ten.

  • Why is a quiet failure after flattening arguably worse than the permerror it replaced?
    A `permerror` is loud: it appears in every receiver's result for the affected checks and points at the record. Drift fails only the messages from addresses the copy missed, as ordinary `fail` or `softfail`, so it can run for weeks before a per-sender drop in SPF passes is noticed.
  • What would make you refuse flattening for a particular service?
    Ranges that change often or without notice, nested records the service restructures, or no team willing to own the refresh. In those cases the include stays, and the budget is found elsewhere: pruning, literals for our own hosts, or moving that service to its own envelope subdomain.

Flattening is copying a colleague's direct phone number into your contacts instead of asking reception each time: quicker every call, until they change number and your copy quietly reaches no one.

  • Flattening is a one-time fix; once under ten, the record is done.
  • Flattened ranges stay correct because receivers still consult the vendor's include.
  • RFC 7208 recommends flattening every include into literals.
  • If flattening drifts, the record will return permerror and alert us.
  • Ending the flattened record with +all covers any addresses the copy missed.