Look up TXT and SPF records from the command line

· 3 min read

You added a TXT record at your DNS host and want to know whether it is actually live? One command answers that. This guide gives you that command for nslookup, dig, PowerShell and host, explains what comes back, and lists the mistakes that show up most often.

Create an SPF record

TXT record lookup: the command for each tool

Windows always has nslookup; Linux and macOS add dig and host. Pick your tool and put in your domain. SPF is an ordinary TXT record on the domain itself, so the SPF lookup is the same query with a filter.

What to check
Tool

Only inserted into the commands in your browser.

All TXT records · dig · Linux, macOS

+short prints only the content, one TXT record per line in quotes. Drop +short to see the TTL and the response status as well.

Shell
dig +short TXT example.com
Sample output
"v=spf1 -all"

All TXT records · nslookup · Windows, Linux, macOS

The command is the same on Windows, Linux and macOS; the output shown is from Linux and macOS, on Windows it wraps differently and the value sits on its own line below "text =". "Non-authoritative answer" only means the reply came from your resolver's cache, not straight from the domain's name server.

Shell
nslookup -type=TXT example.com
Sample output
Server:		192.0.2.53
Address:	192.0.2.53#53

Non-authoritative answer:
example.com	text = "v=spf1 -all"

All TXT records · PowerShell · Windows

Resolve-DnsName returns objects; the Strings property holds the record text. Without the second half you get a table with Name, Type, TTL and Strings.

PowerShell
Resolve-DnsName -Name example.com -Type TXT | Select-Object -ExpandProperty Strings

All TXT records · host · Linux, macOS

host ships with most Linux systems and macOS and answers with one sentence per record, handy for a quick look.

Shell
host -t TXT example.com
Sample output
example.com descriptive text "v=spf1 -all"

SPF · dig · Linux, macOS

SPF lives in a TXT record on the domain itself. The filter keeps only the line that starts with v=spf1. Two lines back means SPF is invalid.

Shell
dig +short TXT example.com | grep -i "v=spf1"
Sample output
"v=spf1 -all"

SPF · nslookup · Windows, Linux, macOS

nslookup cannot filter: look for the line with v=spf1. On Windows append "| findstr spf1", on Linux and macOS "| grep spf1".

Shell
nslookup -type=TXT example.com
Sample output
Non-authoritative answer:
example.com	text = "v=spf1 -all"

SPF · PowerShell · Windows

Where-Object keeps only records whose text starts with v=spf1. An empty result means there is no SPF record.

PowerShell
Resolve-DnsName -Name example.com -Type TXT | Where-Object { $_.Strings -match '^v=spf1' } | Select-Object -ExpandProperty Strings

SPF · host · Linux, macOS

The same lookup with host, filtered down to the SPF record.

Shell
host -t TXT example.com | grep -i "v=spf1"
Sample output
example.com descriptive text "v=spf1 -all"

If nothing comes back, there is no TXT record at that name. That is different from an error: without +short dig reports status NOERROR with zero answers, and nslookup prints "No answer".

Checking a record you just created

Your router and your ISP keep answers for as long as the TTL says, so right after saving you often still see the old state. Skip the caches and ask the responsible name server: find the domain's name servers first, then pass one of them after the @.

Shell
dig +short NS example.com
dig +short TXT example.com @ns1.example.net

# nslookup: name server as the last argument
nslookup -type=TXT example.com ns1.example.net

If the record is there, it is saved correctly and every other resolver will follow once its cached copy expires. If it is not, the problem sits in the DNS editor: wrong name, not saved, or the domain does not use that provider's name servers at all.

Reading the output

Four details cause most of the confusion:

  • The quotes are presentation, not part of the value. Enter the text without them in your DNS editor or they end up in the record twice.
  • A long record shows up as several chunks on one line ("v=DKIM1; p=MIIB…" "…QAB"). A single string holds at most 255 characters; receivers join the chunks without spaces.
  • Several lines are several TXT records. That is normal (verification codes from Google, Microsoft and others); only v=spf1 must exist exactly once.
  • The number before IN in the long dig output is the TTL in seconds. If it counts down between queries, the answer comes from a cache.

Common errors and what causes them

What you see, and why:

  • Empty answer although the record is saved: the name in the editor is wrong. Many providers append the domain themselves, turning "_dmarc.example.com" into "_dmarc.example.com.example.com". Enter only the left part, usually "@" for the domain itself.
  • NXDOMAIN from nslookup or dig: the queried name does not exist at all, often a typo or a subdomain without any record.
  • Two lines with v=spf1: two SPF records make SPF invalid (PermError). Merge them into one.
  • Old value after a change: caching. Ask the authoritative name server as shown above or wait for the TTL.
  • nslookup on Windows resolves "example.com.corp.local": that is the network's DNS suffix being appended. A trailing dot ("example.com.") turns it off.
  • The record exists at your host but nobody sees it: the domain uses other name servers, for example Cloudflare. What counts is what "dig +short NS" returns.

Checking without a terminal

The SPF checker queries the record authoritatively, follows every include and counts the DNS lookups, which is tedious by hand because each level needs another command. It shows whether the ten-lookup limit holds and how the record ends (-all, ~all, ?all). DMARC and DKIM use the same query under a different name; there is a separate guide for those.

What SPF does and does not protect against is covered in the glossary.

Frequently asked questions

What is the nslookup command for a TXT record?
nslookup -type=TXT example.com. To ask a specific name server, append it: nslookup -type=TXT example.com 1.1.1.1. The spelling -q=TXT does the same.
How do I check an SPF record on Linux?
dig +short TXT example.com | grep spf1 prints just the SPF record. If dig is missing, install the package bind9-dnsutils (Debian, Ubuntu) or bind-utils (RHEL, Fedora), or use host -t TXT example.com.
Why does nslookup show my TXT record in several parts?
A TXT string is limited to 255 characters. Longer values such as DKIM keys are split into several strings that the receiver concatenates directly. This is not an error.
How long until a new TXT record is visible?
At the authoritative name server usually right away or within minutes. Resolvers that cached the old state keep serving it until the TTL runs out, typically five minutes to an hour.
Check now

Free SPF record check and lookup: syntax, includes, the 10 DNS lookup limit and the closing qualifier. Shows whether your domain blocks forged senders.

DomainWarn watches the TXT records of all your client domains: when someone changes the SPF record or an entry disappears, you get an alert with a before-and-after diff.

Monitor this domain continuously14-day free trial, no credit card.

More guides