In DNS, which record type carries a domain's SPF policy, and what must the policy's first and last terms be?
answer
- one record type since 2014
- a tag tells SPF text apart
- first match wins, left to right
- an explicit default closes it
basics
~20 sAn 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 sRFC 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
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.
Explain selection: the receiver discards TXT strings not starting with exactly v=spf1, evaluates mechanisms left to right, and ignores anything after all.
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.
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.