Course contentsShow
← Security
Lesson 2298 of 3,05244. Social Engineering and Physical SecurityFree lesson

SPF Record Syntax and Configuration

Creating and configuring SPF records with mechanisms, qualifiers, and proper policy enforcement levels.

SPF Record Syntax and Configuration

What you'll learn: How to construct and configure SPF records using mechanisms, qualifiers, and policy enforcement to prevent email spoofing.

Core Concept

An SPF record is a DNS TXT entry that defines which mail servers can send email on behalf of your domain. Think of it as a guest list at an exclusive club—only servers you've explicitly approved can claim to represent your domain. Proper syntax ensures mail receivers know exactly which sources to trust and how strictly to enforce your policy.

SPF Record Anatomy

An SPF record starts with a version indicator (v=spf1) followed by mechanisms that define authorized sources, and ends with an all mechanism that sets your default policy.

Common Mechanisms

  • ip4:192.0.2.0/24 - Authorizes specific IPv4 addresses or ranges
  • ip6:2001:db8::/32 - Authorizes IPv6 addresses
  • a - Authorizes the domain's A record IPs
  • mx - Authorizes the domain's MX record servers
  • include:domain.com - Imports another domain's SPF policy
  • ptr - Authorizes reverse DNS matches (deprecated, avoid)

Qualifiers

Each mechanism can have a qualifier prefix that controls enforcement:

  • + (pass) - Default; explicitly allows
  • - (fail) - Reject if matched
  • ~ (softfail) - Accept but flag as suspicious
  • ? (neutral) - No policy assertion

Example Records

Strict policy: v=spf1 ip4:203.0.113.10 include:_spf.google.com -all

Permissive during testing: v=spf1 mx include:mailgun.org ~all

The -all qualifier means "reject anything not explicitly authorized," while ~all means "flag but don't reject," useful during migration periods.

Key Takeaway: SPF records use mechanisms to whitelist authorized mail sources and qualifiers to control how strictly violations are enforced—proper configuration requires balancing security (-all) with operational needs, while staying under the 10-DNS-lookup limit to prevent record validation failures.