[ SPF ]

Test SPF using dig, nslookup and a received message

Use DNS queries to inspect publication and a real received message to inspect evaluation. Neither observation alone proves that all sending routes are correctly authenticated.

By the EmailAuth research team · 5 min read

[ Key points ]

  • DNS lookup and SPF evaluation are different observations.
  • Keep TXT record boundaries and actual SMTP inputs intact.
  • Trust only the relevant receiver result and label synthetic fixtures.
On this page

Testing SPF requires two kinds of evidence: what DNS publishes and what a receiver evaluated for a particular message. Dig and nslookup help inspect the first. A trusted Authentication-Results field or receiver-side trace helps inspect the second. Keep those observations connected by the same envelope domain, sending route and time window.

Start with the right domain

Send a representative message through the application you are investigating and preserve its original headers. Identify the envelope identity from trusted receiver evidence, using Return-Path as a clue rather than confusing it with the visible From address. For an empty reverse path, SPF's identity handling involves HELO; do not assume ordinary-message inputs cover that case. RFC 7208 §2.3 and RFC 7208 §2.4 describe the identities.

Write down the sending IP observed by the receiver, the envelope identity, the recipient system and the message time. Do not upload full private headers to an unfamiliar public checker merely to obtain a coloured result. A minimal controlled fixture can often answer the technical question without disclosing unrelated message data.

Inspect the published TXT response

These are illustrative read-only commands. Replace the example name with the domain being evaluated; they are not evidence of tests already run:

dig TXT bounce.example.com.
nslookup -type=TXT bounce.example.com.

The BIND dig manual documents the query utility, and Microsoft's nslookup reference describes query options. Use a trailing dot for an absolute query name, avoiding unintended search-suffix expansion. Keep the full response when troubleshooting, including resolver, status, answer and TTL where shown. A shortened answer can be convenient for reading but omit diagnostic context.

Inspect the actual owner name and select the SPF value from unrelated TXT records. Multiple quoted character strings can belong to one TXT record; SPF treats those strings as concatenated without inserting spaces. Two separate applicable SPF records are a different problem. RFC 7208 §3.2 and RFC 7208 §3.3 define that distinction.

Read a paired synthetic result

The following is a fully synthetic fixture, not observed mail or a production record. Assume the receiver saw a direct connection from documentation address 192.0.2.10, MAIL FROM invoices@bounce.example.com and visible From invoices@example.com. Its DNS response contains one TXT resource record:

bounce.example.com. 300 IN TXT "v=spf1 ip4:192.0.2.10 " "-all"

The two strings within that one record join to v=spf1 ip4:192.0.2.10 -all. The trailing space in the first string separates the mechanisms. For the stated connection, the address mechanism matches and the expected SPF result is pass. A corresponding illustrative receiver result is:

Authentication-Results: mx.receiver.example;
    spf=pass smtp.mailfrom=bounce.example.com

Treat this as trustworthy only under the explicit fixture assumption that mx.receiver.example is the destination's trusted authentication service. A sender could otherwise insert similar text. The example shows SPF evidence only; it does not assert a DKIM, DMARC or delivery result.

Contrast that with this different synthetic DNS answer, which contains two separate applicable records at the same name:

bounce.example.com. 300 IN TXT "v=spf1 ip4:192.0.2.10 -all"
bounce.example.com. 300 IN TXT "v=spf1 ip4:192.0.2.20 -all"

Record selection now returns permerror rather than combining the authorisations. Do not diagnose that situation by counting quotation marks alone; preserve the DNS resource-record boundaries.

Compare resolvers when publication is disputed

If the DNS editor and a recursive query disagree, identify the authoritative nameservers and query a verified authoritative server directly. Dig supports the form dig @server name TXT; substitute an actual verified server and target name. Compare the answer and timestamp with the recursive result. Do not assume the DNS account being edited hosts the delegated zone.

A current authoritative answer and an older recursive answer can indicate caching. A timeout, SERVFAIL and a successful response with no applicable record are different observations. Preserve the exact response before deciding the cause. Avoid repeatedly editing a correct record merely because one observation is stale.

Evaluate the message, not just syntax

A TXT lookup does not execute SPF. A standards-aware evaluator needs the connection IP and relevant SMTP identities, plus the DNS state it resolves. Inspect its trace for the matched mechanism, dependencies and errors. A static record validator may report a structurally acceptable policy without answering whether the real sender passes.

At the destination, read the Authentication-Results inserted by a trusted receiver, not an arbitrary earlier copy. RFC 8601 makes the trust boundary important. Record the SPF result and identity alongside DKIM and DMARC results without treating them as interchangeable.

Keep a reproducible test record

Save the commands, query times, DNS responses, evaluator inputs and redacted received-message evidence. Test each materially different application route and address family in use. Label synthetic fixtures separately from observed results. If the DNS view looks correct but the receiver disagrees, continue with tool pass versus recipient failure rather than declaring that the receiver must be wrong.

DNS background: RFC 1035 section 3.2.1 defines resource-record TTL; RFC 2308 §5 covers negative caching; RFC 8767 §4 updates TTL semantics and permits stale use when authoritative refresh fails. These describe DNS behaviour, not a universal completion time for a change.

Record the next decision

For the single-record fixture, keep the boundary showing two strings inside one record and the joining space; expected SPF is pass for 192.0.2.10. For the two-record fixture, selection fails with permerror before mechanisms are evaluated. Save the trusted-result assumption separately: the printed Authentication-Results text is not independently trustworthy. No command or mail verification was executed here.

[ Takeaway ]

DNS lookup and SPF evaluation are different observations. Keep TXT record boundaries and actual SMTP inputs intact. Trust only the relevant receiver result and label synthetic fixtures.

[ By role ]

What this means for you

Choose your role for practical next steps.

IT / Mail Admin

Keep DNS and message evidence paired.

The identity, sending IP and time must match the question you are diagnosing.

Next steps

  1. Retain full query output.
  2. Verify authoritative hosting when answers differ.
  3. Record the trusted receiver’s evaluated identity.

CISO / SecOps

Control evidence handling.

Authentication headers can contain sensitive operational details and untrusted assertions.

Next steps

  1. Use approved diagnostic tools.
  2. Minimise shared header data.
  3. Document the receiver trust boundary.

Founder / Non-technical

Ask what the test proves.

A successful lookup proves less than a verified business sending route.

Next steps

  1. Identify the application being tested.
  2. Require a received-message observation.
  3. Keep sensitive message data out of unnecessary uploads.

[ FAQs ]

Frequently asked questions

Does dig run SPF evaluation?

No. It queries DNS. Use the retrieved policy with the actual message inputs in a standards-aware evaluator.

BIND dig manual

Which domain should I query?

Use the evaluated envelope domain for the message under investigation, accounting for SPF’s handling of an empty reverse path.

RFC 7208 §2.3 RFC 7208 §2.4

Why do I see several quoted strings?

A single TXT record can contain multiple character strings. Determine the record boundaries before diagnosing duplicate SPF records.

RFC 7208 §3.2 RFC 7208 §3.3

Should I use only dig +short?

It is useful for concise inspection, but keep a full response when investigating status, resolver and TTL differences.

BIND dig manual

Can nslookup replace the received-message test?

No. It shows a DNS observation, not what a specific receiver evaluated during SMTP.

Microsoft nslookup

Which Authentication-Results field should I trust?

Use the result from the receiving system’s trusted authentication boundary. Arbitrary upstream copies can be forged or irrelevant.

RFC 8601 §1.2 RFC 8601 §7.1

Should I paste full headers into a public checker?

Avoid unnecessary disclosure. Use a trusted internal tool or a minimal redacted fixture that preserves the relevant inputs.

What should I save for another administrator?

Keep the exact commands, names, resolver details, times, raw DNS responses, evaluator inputs and trusted receiver results.

[ Sources ]

Sources

  1. RFC 7208

    Sections §2.3 · §2.4 · §3.2 · §3.3 · §4.1 · §4.5 · §5.6

  2. RFC 8601

    Sections §1.2 · §7.1

  3. RFC 1035

    Sections §3.2.1

  4. RFC 2308

    Sections §5

  5. RFC 8767

    Sections §4

  6. BIND dig manual

    Sections dig Synopsis, Simple Usage and Query Options

  7. Microsoft nslookup

    Sections Syntax and Remarks

  8. Microsoft nslookup set type

    Sections Syntax and TXT query type

[ Glossary ]

Glossary

SPF
Authorization evaluation for a connecting IP and the relevant SMTP identity.

RFC 7208 §2.4

DNS TTL
The interval before the source of a cached record must be consulted again; stale use can be permitted when authoritative refresh fails.

RFC 8767 §4

TXT record
One DNS resource record may contain several character strings; SPF joins its strings without adding spaces.

RFC 7208 §3.3

Enterprise provenance

Why top financial institutions and governments retired their email security dashboards.

Traditional email authentication platforms sell you a dashboard and ask your engineers to do the labour. In high-stakes environments, manual oversight means delayed enforcement, configuration drift and unmonitored shadow domains.

EmailAuth is the agentic email provenance platform. Our agents enforce p=reject, keep third-party senders aligned and move your domains to full RFC 9989 compliance, the new DMARC standard,, with human-in-the-loop auditability.

Governments Large enterprises Tier-1 financial institutions

SaaS · Dedicated tenancy · Air-gapped on-prem · BYOK encryption

Knowledge Base