skip to content

SPF

SPF publishes in a DNS TXT record which hosts may send for a domain, and the receiver checks the connecting IP for the MAIL FROM or HELO domain. Interviewers probe lookups and forwarding.

on this pageshow

explore

questions

21

In DNS, which record type carries a domain's SPF policy, and what must the policy's first and last terms be?

level: juniorimportance: must knowfreq 60%

answer

  1. one record type since 2014
  2. a tag tells SPF text apart
  3. first match wins, left to right
  4. an explicit default closes it

basics

~20 s

An SPF policy is published only as a DNS TXT record at the name it covers. Its text must begin with exactly v=spf1, and it should end with an all mechanism that sets the explicit default result.

solid answer

~40 s

RFC 7208 (April 2014) says SPF records MUST be published as `TXT` only; the dedicated SPF record type from the experimental era was dropped. The record sits at the name being checked, the `MAIL FROM` domain or the `HELO` host name, not under a prefix. A receiver keeps only TXT strings that begin with exactly `v=spf1` followed by a space or the end of the string, so the version tag comes first. Mechanisms follow and are tried left to right until one matches, so the record should finish with `all` carrying the domain's chosen qualifier, as in `v=spf1 ip4:192.0.2.0/24 -all`. Mechanisms placed after `all` are ignored, and when nothing matches in a record with neither `all` nor `redirect=`, the result is `neutral`, as if it ended in `?all`.

go deeper

for a junior

Recall three facts: SPF is a TXT record at the domain itself, it starts with v=spf1, and it should end with all carrying the domain's default.

for a middle

Explain selection: the receiver discards TXT strings not starting with exactly v=spf1, evaluates mechanisms left to right, and ignores anything after all.

for a senior

Show you can review a live record: spot terms stranded after all, a misplaced version tag that silently yields none, and syntax errors that turn the whole check into permerror.

for a principal

Frame the record as a published contract: decide who may change it, how changes are checked before publishing, and how the domain's default on all is chosen and documented.

## What an SPF record is An **SPF record** is a domain's published statement of which hosts may use that domain in two SMTP identities: the envelope sender given in `MAIL FROM`, and the host name a client announces in `HELO` or `EHLO`. A receiving server looks the record up while the message is still arriving, compares the connecting IP address with what the record allows, and reaches one of SPF's results. This material is about the record itself: the DNS type that carries it, the name it sits at, and the shape its text must have. What each mechanism matches is covered with SPF mechanisms and qualifiers, and what a receiver does with each result is covered with SPF results. ## The carrier: TXT, and only TXT - **RFC 7208** (April 2014, Standards Track) says SPF records **MUST** be published as a DNS `TXT` record (type 16) only (section 3.1). - During SPF's experimental phase under **RFC 4408** (April 2006), a dedicated SPF record type, number 99, also existed. RFC 7208 dropped it, and a verifier queries for `TXT` only (section 4.4). - The text is US-ASCII. One SPF record is one `TXT` resource record, which may be built from several quoted strings that are joined end to end. Because `TXT` is shared with other uses, such as the verification strings outside services ask a domain to publish, the receiver needs a way to tell the SPF record apart from the rest. That is the job of the version tag. ## The shape of the value The grammar is `version terms`. The receiver takes every `TXT` string at the name and **discards every one that does not begin with exactly `v=spf1`**, where the tag ends at a space or at the end of the record (section 4.5). A record starting `v=spf10` is discarded; so is one in which `v=spf1` appears anywhere but first. | Position | What goes there | Example | |---|---|---| | First | The version tag, exactly `v=spf1` | `v=spf1` | | Middle | Mechanisms, each with an optional qualifier, separated by spaces | `ip4:192.0.2.0/24 mx` | | Last mechanism | `all`, with the qualifier the domain chose | `-all` | | After the mechanisms | Modifiers such as `redirect=` or `exp=`, which SHOULD sit at the end | `exp=explain.example.com` | Mechanisms are evaluated **left to right**, and the first one that matches decides the result. That ordering is why `all`, which matches every address, belongs at the right-hand end. ## Why all goes last 1. **It is the explicit default.** RFC 7208 section 5.1 describes `all` as the rightmost mechanism, providing the result for every address nothing earlier matched. 2. **Anything after it is dead.** Mechanisms listed after `all` MUST be ignored, and a `redirect=` modifier is ignored whenever the record contains `all`, wherever either one sits. A record such as `v=spf1 -all ip4:192.0.2.10` therefore fails mail from 192.0.2.10, because the `ip4` term is never reached. It is not a syntax error, which is exactly what makes the mistake easy to miss in review. 3. **Leaving it off is legal, just vague.** If nothing matches and the record has neither `all` nor `redirect=`, the result is `neutral`, just as if the record ended in `?all` (section 4.7). The RFC recommends ending explicitly because it aids debugging. Which qualifier goes on `all`, `-all` or `~all`, is a policy decision covered with SPF results; this part of the material only fixes where `all` sits. ## A worked record ```dns example.com. 3600 IN TXT "v=spf1 ip4:192.0.2.0/24 mx -all" ``` Read it in order: the version tag first; then an address range and the domain's own mail exchangers as authorised senders; then `-all` as the explicit default for every other address. The shortest record that does something useful, for a name that sends no mail at all, is `v=spf1 -all`. ## Shape mistakes reviewers find - **A missing or misplaced version tag.** The string is not an SPF record at all; if it was the only candidate, the name has no SPF policy and the result is `none`. - **Terms after `all`.** Silently ignored, so a host appended at the end is never authorised. - **Two records that each start `v=spf1`.** The receiver does not merge them; the check returns `permerror`. - **A syntax error anywhere.** RFC 7208 section 4.6 validates the whole record before evaluating it, and any syntax error gives `permerror` with no evaluation at all. - **Publishing under a prefix.** Unlike a DKIM key or a DMARC policy, the SPF record sits at the very name it covers, not under a label. A record at `_spf.example.com` is consulted for example.com only when another record's `include` or `redirect=` points to it.

  • Is a record that leaves out all invalid?
    No. RFC 7208 accepts it: when no mechanism matches and there is no `redirect=`, the result is `neutral`, as if the record ended in `?all`. The RFC still recommends ending with `all` or `redirect=`, because an explicit default is easier to debug and states the domain's intent instead of leaving it implicit.
  • Why must the version tag be exactly v=spf1 followed by a space or the end?
    Because the receiver uses it to pick SPF records out of every `TXT` string at the name. Only strings beginning with exactly `v=spf1`, terminated by a space or the end of the record, survive selection; `v=spf10` or a tag placed later in the string is discarded, so the publisher may have no SPF record at all without realising it.

  • SPF has its own DNS record type that should be published alongside TXT.
  • Terms after all are still checked if an earlier term did not match.
  • The version tag can appear anywhere in the record as long as it is present.
  • A record without all is a syntax error and yields permerror.
  • The SPF record lives under _spf.example.com, like _dmarc for DMARC.
open as a page

What are the seven results an SPF check can return, and how does a receiving mail server typically handle each one?

level: juniorimportance: must knowfreq 60%

basics

~20 s

SPF returns pass, fail, softfail, neutral, none, temperror or permerror. RFC 7208 leaves the action to the receiver: it may reject fail, should not reject on softfail alone, must treat neutral like none, and may defer temperror.

open as a page

What does an SPF record ending in +all authorise, and how do its qualifiers and left-to-right matching produce a result?

level: juniorimportance: must knowfreq 48%

basics

~20 s

An SPF record ending in +all authorises every IP address: all always matches and + makes a match pass. Mechanisms are tried left to right; the first match's qualifier (+ pass, - fail, ~ softfail, ? neutral) is the result.

open as a page

Why does adding a second v=spf1 TXT record at the same domain break SPF for all of its mail, and how do you fix it?

level: middleimportance: must knowfreq 46%

basics

~20 s

RFC 7208 allows one record beginning v=spf1 per name; when a receiver selects two, the check returns permerror for every message from that domain. The fix is to merge both into one record with a single all at the end.

open as a page

Why does SPF fail for mail forwarded through an alias, such as an alumni address, when the original sender's record is correct?

level: middleimportance: must knowfreq 45%

basics

~20 s

SPF checks the IP of the server that connected last. A plain forwarder resends from its own IP but keeps the original MAIL FROM, so the receiver checks the sender's record, which never listed the forwarder.

open as a page

Under RFC 7208, which SPF terms count toward the 10-DNS-lookup limit, and which terms cost nothing?

level: middleimportance: must knowfreq 38%

basics

~20 s

RFC 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.

open as a page

In SPF, how does the include mechanism differ from the redirect= modifier, and when should a domain use each?

level: middleimportance: must knowfreq 38%

basics

~20 s

An SPF include asks another domain's record about the client and matches only on pass; otherwise the parent's own terms and ending decide. redirect= runs only when nothing matched and no all exists, and its target's result becomes the answer.

open as a page

Why did RFC 7208 retire the dedicated SPF DNS record type, number 99, and what do you do with a zone still serving it?

level: middleimportance: should knowfreq 30%

basics

~20 s

RFC 7208 (April 2014) made TXT the only SPF carrier: the older dual TXT and type-99 scheme had no type every publisher had to serve and every verifier to check. Verifiers query TXT only, so keep the policy there and delete type 99.

open as a page

What exactly do the SPF ip4, ip6, a and mx mechanisms match, including their optional domain and prefix-length forms?

level: middleimportance: should knowfreq 30%

basics

~20 s

SPF ip4 and ip6 match the client address against a written network (default /32, /128); a matches a host name's A or AAAA addresses; mx matches the addresses of a domain's MX hosts. a and mx default to the checked domain.

open as a page

Why does RFC 7208 say the SPF ptr mechanism SHOULD NOT be published, and what replaces it in an existing record?

level: middleimportance: should knowfreq 22%

basics

~20 s

RFC 7208 says SPF's ptr SHOULD NOT be published: it is slow, less reliable under DNS errors and burdens the reverse-DNS servers, though checkers must still support it. Replace it with ip4, ip6 or a terms for the hosts it covered.

open as a page

In an SPF review of example.com, which DNS names need their own v=spf1 record, given that the apex record does not cover subdomains?

level: seniorimportance: should knowfreq 26%

basics

~20 s

Every name a receiver will check needs its own record: each domain used in MAIL FROM, each host name announced in HELO, and each name that sends no mail, which gets v=spf1 -all. SPF never inherits from a parent domain.

open as a page

How does the Sender Rewriting Scheme (SRS) let a mail forwarder pass SPF while bounces still reach the original sender, and why is the rewritten address signed?

level: seniorimportance: should knowfreq 24%

basics

~20 s

SRS rewrites MAIL FROM to an address in the forwarder's own domain that encodes the original sender, so receivers check the forwarder's SPF record. Bounces return there, are verified by hash and timestamp, and are relayed back.

open as a page

An SPF check returns temperror for one sender and permerror for another; what does each mean, and how should the receiving mail server respond?

level: seniorimportance: should knowfreq 20%

basics

~20 s

Temperror is a transient, usually DNS, failure a retry may clear: accept, or defer with 451. Permerror is a record that cannot be interpreted until its DNS operator fixes it: reject with 550, or accept and annotate.

open as a page

An SPF record started returning permerror after a sixth hosted sending service was added; how do you count its DNS lookups by hand?

level: seniorimportance: should knowfreq 26%

basics

~20 s

Resolve the record as a receiver would: count each include, a, mx, ptr, exists and redirect, then open every include and add its counted terms, recursively, ignoring ip4, ip6, all and exp. A total above ten is the permerror.

open as a page

For an organisation's SPF records, how do you as the lead decide whether each domain should end in -all or ~all?

level: principalimportance: should knowfreq 30%

basics

~20 s

-all makes unlisted hosts fail; ~all makes them softfail, which RFC 7208 says should not alone cause rejection. Decide per domain from how complete the sender inventory is, how much mail is forwarded, and whether DMARC enforcement and DKIM carry protection.

open as a page

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%

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.

open as a page

When consolidating a company's SPF record, how do you decide which outside services get an include in the main domain's record, given what an include authorises?

level: principalimportance: should knowfreq 16%

basics

~20 s

An SPF include authorises whatever the service's record passes, live and under the service's control, shared pools included. Include a service in the main domain only if it sends with that domain in its envelope and its record is narrow.

open as a page

After a domain's SPF record grows past 255 characters, how should its TXT value be split, and why keep the whole answer under 512 octets?

level: seniorimportance: nice to knowfreq 16%

basics

~20 s

Split the value into quoted strings of at most 255 octets inside one TXT record; receivers join them with no added space. RFC 7208 says the answer SHOULD fit 512 octets, planning on 450 for the name plus all its TXT records.

open as a page

For a bounce with an empty MAIL FROM, which identity does an SPF verifier check, and how does the separate HELO check relate to it?

level: seniorimportance: nice to knowfreq 12%

basics

~20 s

With a null reverse-path, RFC 7208 defines the MAIL FROM identity as postmaster@ the HELO name. The separate HELO check, RECOMMENDED and run first when both are done, evaluates that same host name, so its SPF record decides both.

open as a page

What is an SPF void lookup under RFC 7208, and how can a retired vendor's leftover entry push a record into permerror?

level: seniorimportance: nice to knowfreq 12%

basics

~20 s

A void lookup is an SPF term's DNS query answered with NXDOMAIN or zero records; verifiers SHOULD allow two and return permerror beyond that. A leftover include is worse: a target with no SPF record gives permerror on its own.

open as a page

What do SPF macros such as %{i}, %{s} and %{d} let the exists mechanism and the exp= modifier do, and what do they cost?

level: seniorimportance: nice to knowfreq 9%

basics

~20 s

SPF macros insert values such as the client IP (%{i}), sender (%{s}) and domain (%{d}) into names. exists matches when the built name has any A record; exp= fetches explanation text for a fail. Sender macros defeat caching and expose senders.

open as a page