What exactly do the SPF ip4, ip6, a and mx mechanisms match, including their optional domain and prefix-length forms?
answer
- the connecting client's address
- missing prefix means one host
- a follows the connection's family
- mx means inbound hosts, by name
- no implicit MX fallback
basics
~20 sSPF 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.
solid answer
~40 sAll four compare one address: the IP of the SMTP client connected to the receiver. `ip4:` and `ip6:` take a written network; without a prefix length they mean exactly one host (`/32`, `/128`), and a partial address like `192.0.2` is not allowed. `a` resolves a host name, by default the domain being checked, and matches if the client is one of its A records on an IPv4 connection or AAAA records on IPv6. `mx` looks up a domain's MX hosts and then their addresses, and it never falls back to the domain's own address the way SMTP's implicit-MX rule does. Both take an optional domain and a dual prefix such as `a:relay.example.com/28//64`. RFC 7208 advises `ip4`/`ip6` over `a`, and `a` over `mx`, unless the hosts change often.
go deeper
Recall that SPF compares the connecting client's address, and that ip4 and ip6 hold literal networks while a and mx resolve names.
Explain the default prefix lengths, the dual prefix on a and mx, the connection-family rule for a, and why mx has no implicit-MX fallback.
Map a real outbound architecture to terms: which hosts are the last hop, which addresses are stable, and where mx quietly authorises inbound-only or third-party hosts.
Weigh explicit address lists, which need updating on every renumbering, against name-based terms that follow DNS but widen what the record trusts.
## The address every mechanism compares An SPF check compares one address: the IP of the **SMTP client** that connected to the receiver doing the check (RFC 7208 calls it `<ip>`). That is the last hop into the receiver, not the machine where the message was written. Two consequences matter when a company consolidates its senders: - An office printer that hands its scan-to-email messages to the company's own outbound gateway needs **no term of its own**: receivers see the gateway's address, which is already listed. - A device or service that delivers **directly** to other domains' servers needs its own address, or its operator's record, in the policy. Every designated-sender mechanism follows the same comparison rule (section 5): with no prefix length, the two addresses must be equal; with a prefix length, only that many high-order bits are compared. ## ip4 and ip6: networks you write down `ip4:` and `ip6:` hold a literal network and match when the client address falls inside it. - `ip4:192.0.2.25` with no prefix means `/32`, one host. - `ip6:2001:db8:25::1` with no prefix means `/128`, one host. - `ip4:198.51.100.32/28` matches the sixteen addresses 198.51.100.32 to .47. - Omitting octets is not a shorthand: `ip4:192.0.2` is invalid, and `192.0.2.0/24` must be written instead. - IPv4 addresses are listed only with `ip4`; an `ip6` term never stands in for them. These are the most predictable mechanisms because the record itself holds the answer. Use the narrowest prefix that covers the hosts that really send: writing a whole office `/24` when one NAT address sends mail authorises 255 other addresses that never should. ## a: whatever a host name resolves to `a` matches if the client address is one of a host name's addresses. The name is the **domain being checked** unless one is given (`a:relay.example.com`). The lookup type follows the connection: **A records for an IPv4 client, AAAA records for an IPv6 client**, so `a` also covers IPv6 even though its name says otherwise. A **dual prefix length** widens the match: `a:relay.example.com/28//64` compares the first 28 bits of the relay's IPv4 addresses on IPv4 connections and the first 64 bits of its IPv6 addresses on IPv6 connections. A name with no address of the right family simply does not match. ## mx: your inbound servers, by name `mx` first looks up the MX records of a domain (by default the one being checked, or `mx:example.org`), then the addresses of each MX host, and matches if the client is any of them. It accepts the same optional prefix lengths as `a`. Two traps catch administrators: 1. `mx` authorises the hosts that **receive** the domain's mail. If outbound mail leaves through a different gateway, `mx` adds nothing useful; if inbound mail is handled by an outside filtering service, `mx` authorises that service's hosts to send as the domain. 2. If the domain has **no MX record**, the mechanism must not fall back to the domain's own A or AAAA addresses, as SMTP delivery would under its implicit-MX rule (section 5.4). It simply does not match. ## Choosing a mechanism for each sender | Sender | Good fit | Why | |---|---|---| | Own outbound gateway on fixed addresses | `ip4:` / `ip6:` | The record holds the truth; nothing to resolve | | Relay whose addresses change with redeployments | `a:relay.example.com` | Renumbering needs only a DNS change on the host name | | Gateway that is also the inbound MX | `mx` or `ip4:` | `mx` follows MX changes; `ip4` is cheaper and explicit | | Printers relaying through the gateway | nothing | Receivers only see the gateway's address | | Printers sending directly from an office range | a narrow `ip4:` | List the NAT address, not the whole office block | RFC 7208 section 10.1.2 states the trade-off directly: `a` allows easy renumbering and `mx` lets the set of mail hosts change easily, but unless such changes are common, the less resource-intensive `ip4`/`ip6` are better than `a`, and `a` is better than `mx`. How each name-based term spends the record's DNS lookup budget is covered with the lookup limit. A consolidated record for the company in this example could read `v=spf1 ip4:192.0.2.25 ip6:2001:db8:25::/64 a:relay.example.com ip4:198.51.100.40/30 -all`: the gateway by address, the relay by name, and only the office NAT addresses that send directly.
- Why might mx authorise hosts that never send the domain's mail?`mx` matches the addresses of whatever hosts the domain's MX records name, and those are the inbound servers. When outbound and inbound are separate, the term authorises receive-only machines; when an outside filtering service takes inbound mail, it authorises that service's hosts to send with the domain. List outbound hosts with `ip4`, `ip6` or `a` instead.
- Does a bare a mechanism cover a host's IPv6 address?Yes. RFC 7208 section 5.3 performs the lookup that matches the connection: A records for an IPv4 client and AAAA records for an IPv6 client. To widen both families at once, use a dual prefix such as `a/24//64`, where the first length applies to IPv4 and the second to IPv6.
- ip4:203.0.113.0 without a prefix covers the whole /24.
- The a mechanism only ever checks IPv4 A records.
- If a domain has no MX record, mx falls back to the domain's own address.
- SPF checks the address of the machine where the message was composed.
- Every office printer needs its own SPF term even when it relays through the gateway.