SPF stands for Sender Policy Framework. According to Wikipedia, SPF is a framework that aids in protecting forged emails from a given domain. It was first introduced in early 2000 but wasn't officially standardized until 2014, with the publication of RFC 7208. In simple terms, SPF provides a way for receiving email servers to validate that email sent to them is legitimate, which cuts down on email SPAM.
SPF is implemented by adding several TXT Domain Name Server (DNS) records for a given domain name sending emails.
Let us look at how redhat.com uses SPF with dig:
$ dig +short redhat.com TXT | grep spf "v=spf1 ip4:22.214.171.124 ip4:126.96.36.199 ip4:188.8.131.52 ip4:184.108.40.206 ip4:220.127.116.11 ip4:18.104.22.168/21 ip4:22.214.171.124/16 ip4:126.96.36.199/20 ip4:188.8.131.52/20 ip4:184.108.40.206/21 ip4:220.127.116.11 ip4:18.104.22.168 ip4:22.214.171.124 ip4:126.96.36.199 ip" "4:188.8.131.52/16 ip4:184.108.40.206 ip4:220.127.116.11 ip4:18.104.22.168 ip4:22.214.171.124 include:spf1.redhat.com -all"
Look at the TXT record returned. There are four keywords that you need to understand:
- ip4 - Provides the IPv4 addresses of all the email servers from which the given domain can legitimately send email. The format can be a single IPv4 host or an IPv4 network with a CIDR subnet mask.
- include - Provides additional sub-domains approval to send email on behalf of the parent domain.
- -all - Specifies that no other IPv4 address should be trusted as a valid email sender.
There are three options for all:
- -all - Also known as "dash all," again, means emails sent by IPv4 addresses not specifically listed in the TXT record should be rejected.
- ~all - Also known as "tilde all," means emails sent by IPv4 addresses not specifically listed in the TXT record should probably be flagged as SPAM.
- +all - Also known as "plus all," means emails sent by any and all IPv4 addresses from a given domain be authorized. This is highly discouraged.
When thinking about security, less access is more. Please configure the SPF domain records with legitimate, authorized email servers for sending email. This helps protect that domain from being victimized.
[ You might also like: A sysadmin's guide to configuring an email server ]
How it works
A Red Hat employee sends an email via a Red Hat mail server to a Google Gmail recipient. Google's email protection server layer performs an SPF inquiry via a DNS TXT record lookup against redhat.com DNS. The redhat.com DNS responds with the following TXT record:
"v=spf1 ip4:126.96.36.199 ip4:188.8.131.52 ip4:184.108.40.206 ip4:220.127.116.11 ip4:18.104.22.168 ip4:22.214.171.124/21 ip4:126.96.36.199/16 ip4:188.8.131.52/20 ip4:184.108.40.206/20 ip4:220.127.116.11/21 ip4:18.104.22.168 ip4:22.214.171.124 ip4:126.96.36.199 ip4:188.8.131.52 ip" "4:184.108.40.206/16 ip4:220.127.116.11 ip4:18.104.22.168 ip4:22.214.171.124 ip4:126.96.36.199 include:spf1.redhat.com -all"
The Google SPF inquiry parses the response, looks at the email envelope-sending email server address, and tries to match that against the IPv4 addresses in the list provided. If it matches, Google knows this is a legitimate email sent from an approved Red Hat email server. If the information doesn't match, then it assumes that the email envelope has been forged/altered and blocks or marks it as SPAM to protect the recipient.
How to implement
To create an SPF record for a domain name, you need to provide the following DNS record in your domain's authoritative name server.
example.com. IN TXT “v=spf1 ipv:192.168.100.200 -all”
This record now advertises that legitimate emails will only be sent via the IPv4 address of 192.168.100.200 from the domain example.com. All others should be rejected.
[ Want to test your sysadmin skills? Take a skills assessment today. ]
SPF is one of three common DNS-based configuration options email administrators have at their disposal. Stay tuned as I introduce Domain-based Message Authentication (DMARC) and DomainKeys Identified Mail (DKIM) configuration options in future blog postings.