How to Find SPF Records with dig Command?

Published July 11, 2024

Problem: Locating SPF Records

SPF (Sender Policy Framework) records are important for email administrators and security professionals. These records help with email authentication, prevent email spoofing, and improve deliverability. Finding SPF records can be difficult without the right tools. The 'dig' command, a DNS lookup utility, can help with this task, but many users may not know how to use it for this purpose.

How to Use dig to Find SPF Records

Basic SPF Record Lookup

To find SPF records using dig, query the TXT records of a domain. The basic command syntax is:

dig TXT

For example, to look up the SPF record for, use:

dig TXT

This command will return all TXT records for the domain, including the SPF record if one exists.

Tip: Filtering SPF Records

To filter out non-SPF TXT records, you can use grep with your dig command:

dig TXT | grep "v=spf1"

This will only display lines containing SPF records, making it easier to find the information you need.

Querying Specific Name Servers

You can query a specific name server for SPF records. Add the @ symbol followed by the name server address to your dig command:

dig TXT @nameserver.address

For instance, to query the SPF record for using Google's public DNS server:

dig TXT @

Interpreting SPF Record Output

When you run a dig command for SPF records, you'll see output with several sections. The main part is the "ANSWER SECTION," which includes the TXT records.

SPF records usually start with "v=spf1" and may include mechanisms and qualifiers. For example:

"v=spf1 ~all"

In this record:

  • "v=spf1" shows the SPF version
  • "" specifies another domain to check for authorized IP addresses
  • "~all" is a softfail directive, suggesting that any IP not matching the previous mechanisms should be treated as suspicious but not rejected

Alternative Methods for Finding SPF Records

Using Online SPF Record Lookup Tools

Web-based SPF record lookup tools offer an alternative to command-line utilities. These online services let you input a domain name and get SPF record information through a user-friendly interface. Some options include MXToolbox and SPF Record Checker.

Advantages of online tools:

  • Easy to use, especially if you're not familiar with command-line interfaces
  • Often provide extra information and explanations about the SPF record
  • Accessible from any device with a web browser

Limitations compared to dig:

  • Depend on third-party services and their availability
  • Potential privacy issues when querying sensitive domains
  • May not offer as much flexibility or customization as command-line tools

Checking SPF Records with nslookup

nslookup is another command-line tool for querying DNS servers. While not as flexible as dig, you can use it to find SPF records.

To use nslookup for SPF record lookup:

  1. Open a terminal or command prompt
  2. Type nslookup and press Enter to start the nslookup interactive mode
  3. Set the query type to TXT by typing set type=txt
  4. Enter the domain name you want to check


> set type=txt

This will show all TXT records for the domain, including the SPF record if present. Look for the record starting with "v=spf1" to identify the SPF information.

While nslookup is available on most operating systems by default, it offers fewer options for customizing queries compared to dig. However, it can be useful when dig is not available or when you prefer a simpler interface.