The tutorial you are following explains one basic Postfix+Dovecot setup, as explained in the first part. I don't like the attitude of setting up SPF and DKIM to get through spam filters, as the purpose of SPF is to prevent others from using your domain as an envelope sender and the purpose of DKIM is to authenticate the domain has authorized this message and that the signed contents haven't been modified.
The author of the tutorial has taken some shortcuts, and while he has explained all the steps pretty well and justified some of his own solutions, it says little about what settings could or should be changed to suit your own needs.
Let's take a look at the record given in the tutorial, and debunk the flaws in the explanation.
TXT @ "v=spf1 mx ~all"
TXT indicates this is a TXT record.
@ in the name field.
v=spf1 indicates this is an SPF record and the SPF record version is SPF1.
@ is replaced with the variable in e.g.
$ORIGIN example.com., meaning this record would be for the domain apex i.e.
example.com. IN TXT.
mx means all hosts listed in the MX records are allowed to send emails for your domain and all other hosts are disallowed.
You could use the
mx mechanism if the same servers that are used for receiving mail are also sending mail. This is not always true in bigger configurations, and sometimes there are additional sources for outbound mail that won't be used for receiving messages, like newsletter systems. As the
mx mechanism requires additional DNS queries first for the
MX records and then for the corresponding
A records, it's usually better to use
ip6 mechanisms to tell the allowed IP addresses (or CIDR) directly.
~all indicates that emails from your domain should only come from hosts specified in the SPF record. Emails that are from other hosts
will be flagged as forged. Possible alternatives are
?all, but they are rarely used.
~ means SoftFail, so it doesn't prevent anyone from using your domain, but may be used for spam scoring. The
-all is not "rarely used", but is the probably correct qualifier for generating a hard Fail result allowing rejecting the message altogether.
With these corrections an SPF record for allowing messages from two servers alone would be e.g.
example.com. IN TXT "v=spf1 +ip4:192.0.2.88 +ip4:198.51.100.61 -all"
DKIM has selectors (RFC 6376, 3.1) for allowing multiple sources to sign messages for the same domain without sharing the keys. This tutorial uses
default as the selector, but could replace it e.g. with the name of the server to make it unique. Then you can have separate signing keys on both servers and publish the public keys accordingly, e.g.
mailserver._domainkey.example.com. IN TXT "v=DKIM1; h=sha256; k=rsa; " "p=...
newsletter._domainkey.example.com. IN TXT "v=DKIM1; h=sha256; k=rsa; " "p=...
A hint: it's easy to see what you should modify if you hilight all the occurrences of word
default in the tutorial using the search tool in your browser.