Set Up OpenDMARC With Postfix On CentOSRHEL To Block Email Spoofing
Set Up OpenDMARC With Postfix On CentOSRHEL To Block Email Spoofing
In previous articles, we discussed several effective tips to block email spam. This
tutorial will be showing you how to set up OpenDMARC with Postfix SMTP server on
CentOS/RHEL to block email spoofing and spam. OpenDMARC is an open source
DMARC email policy filter for MTAs (Message Transport Agent, aka SMTP server).
What is DMARC
DMARC (Domain-based Message Authentication, Reporting and Conformance) is an
Internet standard (RFC 7489) that allows domain owners to prevent their domain
names from being used by email spoofers. Before DMARC is invented, it is very easy for
bad actors to use other people’s domain name in the From address.
If a domain owner created DMARC DNS record for his/her domain name and a
receiving email server implemented DMARC verification, then bad actors need to pass
SPF alignment or DKIM alignment in order to pass DMARC verification. If DMARC
check fails, the spoofed email could be rejected. Never to be seen by end users. It’s
difficult for the bad actor to pass SPF or DKIM, unless the domain owner’s email server
is compromised.
Then I checked the email headers, which shows SPF failed. There’s no DKIM signature.
So DMARC check fails. This is a spoofed email.
This goes to show that not only big brands are being used by email spoofers, any
domain names on the Internet could be impersonated by bad actors. Unfortunately the
DMARC policy for this domain name is p=none , which tells receiving email server to
do nothing special if DMARC check fails. If the policy is to p=reject , then my Postfix
SMTP server would reject this email with OpenDMARC.
Paypal and Facebook have created a reject DMARC policy for their domain name.
2/11
So if a bad actor tries to spoof Paypal or Facebook, my email server can reject the
spoofed email with OpenDMARC. There are many other well-known domain names that
deployed a reject DMARC policy, as can be seen in the table below.
The secure mailbox provider Protonmail is using Postfix and OpenDMARC to perform
DMARC checks on inbound emails and I will show you how to do the same on your own
Postfix SMTP server.
Prerequisites
This tutorial is for mailbox providers and anyone who run their own mail server, to
protect their users from being scammed by email spoofing. If you are a domain name
owner and want to prevent your domain name from being used by email spoofers,
please read this article to create DMARC record and analyze DMARC report. I also
recommend you to read that article if you don’t fully understand DMARC.
You should have a DKIM verification service running on your mail server before you set
up OpenDMARC. OpenDMARC should be used in conjunction with OpenDKIM. If you
use Amavis to do DKIM signing and verification, then I recommend switching from
Amavis to OpenDKIM. That’s because OpenDMARC can’t read the DKIM verification
results from Amavis. You don’t have to completely uninstall Amavis. Simply disable
DKIM in Amavis, then install and configure OpenDKIM.
If you don’t like to switch to OpenDKIM, then you need to integrate Amavis with Postfix
via the milter interface, which will be explained at the end of this article.
Start OpenDMARC.
3/11
OpenDMARC listens on 127.0.0.1:8893 . Run the following command to check its
status.
Output:
Then edit the main configuration file with your text editor.
# AuthservID name
By default OpenDMARC uses the MTA hostname as the AuthserveID, but it’s better to
use a different name for the authentication service, because Amavisd-new will overwrite
the authentication results header added by OpenDMARC. You can change it to the
following, which will be very easy for you to see which program adds which
authentication-results header.
AuthservID OpenDMARC
Next, add the following line. Replace the hostname with your real Postfix hostname.
This tells OpenDMARC to trust authentication result with mail.yourdomain.com in the
ID. This is needed when you have OpenDKIM running to do DKIM verification. If the
Postfix hostname isn’t included in the TrustedAuthservIDs , then OpenDMARC will
ignore the Authentication-Results header generated by OpenDKIM.
TrustedAuthservIDs mail.yourdomain.com
# IgnoreAuthenticatedClients false
4/11
Change the value to true to ignore SMTP clients that are successfully authenticated via
SMTP AUTH, which includes desktop/mobile mail clients that submit outgoing emails
over port 587.
IgnoreAuthenticatedClients true
# RejectFailures false
By default, OpenDMARC won’t reject emails that fail DMARC check, even if the
domain’s policy is set to p=reject . If you prefer to reject emails that fail DMARC check
when the domain’s policy is set to p=reject , then uncomment this line and change
false to true .
RejectFailures true
# RequiredHeaders false
Change it to:
RequiredHeaders true
This will reject emails that don’t conform to email header standards as described in
RFC5322. For example, if an incoming email doesn’t have From: header or date:
header, it will be rejected. A From: field from which no domain name could be
extracted will also be rejected.
By default, OpenDMARC on CentOS/RHEL will ignore any SPF results in the email
headers and performs SPF checks itself. This is controlled by the following two
parameters.
SPFIgnoreResults true
SPFSelfValidate true
If you prefer to use other SPF check service on your mail server, then tell OpenDMARC
to trust SPF results in the email headers and only perform SPF checks when it can’t find
SPF results in the headers.
SPFIgnoreResults false
SPFSelfValidate true
Save and close the file. Then restart OpenDMARC for the changes to take effect.
If you followed my DKIM tutorial on CentOS 8/RHEL 8, then you should have lines in
this file like below. OpenDKIM is listening on 127.0.0.1:8891 .
# Milter configuration
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
Now you just need to add the OpenDMARC socket so that Postfix can talk to
OpenDMARC. (Make sure it’s after the OpenDKIM socket.) OpenDMARC listens on
127.0.0.1:8893 .
# Milter configuration
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:127.0.0.1:8891,inet:127.0.0.1:8893
non_smtpd_milters = $smtpd_milters
Save and close the file. Then restart Postfix for the change to take effect.
Install OpenDKIM from the EPEL (Extra Packages for Enterprise Linux) repository.
KeyFile /etc/opendkim/keys/default.private
6/11
Since we don’t want OpenDKIM to sign outgoing emails, we need to comment out this
line, then save and close the file.
Add the following lines at the end of this file, so Postfix will be able to call OpenDKIM
via the milter protocol. Note that you should use 127.0.0.1 as the address. Don’t use
localhost .
# Milter configuration
milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:127.0.0.1:8891,inet:127.0.0.1:8893
non_smtpd_milters = $smtpd_milters
Save and close the file. Then add postfix user to opendkim group.
I sent an email from my Gmail account to my domain email address and it passed
DMARC verification. If you don’t see this email header, then check your mail logs.
telnet mail.yourdomain.com 25
Then use the following steps to send a spoof email. (You type in the bold texts.)
HELO mail.paypal.com
250 mail.yourdomain.com
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
From: [email protected]
To: [email protected]
Subject: Please update your password.
As you can see, my mail server rejected this email because it didn’t pass DMARC check
and Paypal deployed a p=reject policy.
8/11
Amavisd-milter listens on Unix socket at /run/amavisd/amavisd-milter.sock . Edit
Postfix main configuration file.
Add the following lines at the end of the file. Note that you should place the amavisd-
milter Unix socket before the OpenDMARC TCP socket.
# Milter configuration
milter_default_action = accept
milter_protocol = 6
smtpd_milters = unix:/run/amavisd/amavisd-milter.sock,inet:127.0.0.1:8893
non_smtpd_milters = $smtpd_milters
Also comment out the following line, so Postfix won’t pass incoming emails to Amavis
twice.
content_filter = smtp-amavis:[127.0.0.1]:10024
Save and close the file. Then add postfix to the amavis group, so Postfix will be able
to access the Amavis Unix socket.
Outgoing emails submitted from authenticated users should not be passed to Amavis
via the milter interface, because Amavis won’t add DKIM signature. They should use
127.0.0.1:10026 as usual, so that DKIM signature will be added. Edit the Postfix
master.cf file.
Find the submission component. It should look as follows if you followed my Amavis
tutorial on CentOS/RHEL.
-o smtpd_milters=
Like this:
9/11
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_tls_wrappermode=no
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o content_filter=smtp-amavis:[127.0.0.1]:10026
-o smtpd_milters=
This will make the Postfix submission serivce use no milter at all, so that emails
submitted from authenticated users won’t be passed to Amavis via the milter interface.
Note that you should not add any space before the equal sign (=).
Save and close the file. Restart Postfix for the changes to take effect.
Now OpenDMARC will be able to read the DKIM verification result from Amavis, and
Amavis will continue adding DKIM signature for authenticated users.
Wrapping Up
I hope this tutorial helped you set up OpenDMARC with Postfix SMTP server on
CentOS/RHEL to block email spoofing and spam. As always, if you found this post
useful, then subscribe to our free newsletter to get more tips and tricks. Take care
[Total: 2 Average: 5]
You may also like:
10/11
How to Set Up OpenDKIM on CentOS 8/RHEL 8 Mail Server
Part 4: Set Up SPF and DKIM with Postfix on CentOS 8/RHEL 8 Mail Server
Run Your Own Email Server on CentOS 8/RHEL 8 - Postfix SMTP Server
Install Dovecot IMAP Server on CentOS 8/RHEL 8 & Enable TLS Encryption
11/11