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.

Set Up OpenDMARC with Postfix on CentOS/RHEL to Block Email Spoofing centos CentOS Server DMARC linux OpenDMARC Red Hat Red Hat Server Redhat

Email Spoofing Example

A spammer sent me a ransom email using <span data-bind="text: viewFrom, title: viewFrom" title=""lOi" ">winsaaluminyumankara.com in the From address. The whois information of <span data-bind="text: viewFrom, title: viewFrom" title=""lOi" ">winsaaluminyumankara.com is public. Clearly the spammer is not a person responsible for this domain name.

Set Up OpenDMARC with Postfix on CentOS/RHEL to Block Email Spoofing centos CentOS Server DMARC linux OpenDMARC Red Hat Red Hat Server Redhat

<span data-bind="text: viewFrom, title: viewFrom" title=""lOi" ">winsaaluminyumankara.com has a DMARC record.

Set Up OpenDMARC with Postfix on CentOS/RHEL to Block Email Spoofing centos CentOS Server DMARC linux OpenDMARC Red Hat Red Hat Server Redhat

Then I checked the email headers, which shows SPF failed. There’s no DKIM signature. So DMARC check fails. This is a spoofed email.

Set Up OpenDMARC with Postfix on CentOS/RHEL to Block Email Spoofing centos CentOS Server DMARC linux OpenDMARC Red Hat Red Hat Server Redhat

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.

Set Up OpenDMARC with Postfix on CentOS/RHEL to Block Email Spoofing centos CentOS Server DMARC linux OpenDMARC Red Hat Red Hat Server Redhat

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.

  • bankofamerica.com
  • yahoo.com
  • chase.com
  • wellsfargo.com
  • facebook.com
  • google.com
  • youtube.com
  • twitter.com
  • reddit.com
  • instagram.com
  • linkedin.com
  • medium.com
  • pinterest.com
  • dropbox.com
  • microsoft.com
  • whatsapp.com

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.

Setting up OpenDMARC with Postfix SMTP Server on CentOS/RHEL

OpenDMARC is an open source software that can perform DMARC check and reporting. You can install it on CentOS/RHEL from the EPEL repository.

sudo dnf install epel-release

sudo dnf install opendmarc

Start OpenDMARC.

sudo systemctl start opendmarc

Enable auto-start at boot time.

sudo systemctl enable opendmarc

OpenDMARC listens on 127.0.0.1:8893. Run the following command to check its status.

systemctl status opendmarc

Output:

 opendmarc.service - Domain-based Message Authentication, Reporting & Conformance (DMARC) Milter
   Loaded: loaded (/usr/lib/systemd/system/opendmarc.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-03-08 23:52:59 EDT; 1min 4s ago
     Docs: man:opendmarc(8)
           man:opendmarc.conf(5)
           man:opendmarc-import(8)
           man:opendmarc-reports(8)
           http://www.trusteddomain.org/opendmarc/
 Main PID: 19987 (opendmarc)
    Tasks: 3 (limit: 5047)
   Memory: 1.1M
   CGroup: /system.slice/opendmarc.service
           └─19987 /usr/sbin/opendmarc -c /etc/opendmarc.conf -P /var/run/opendmarc/opendmarc.pid

Then edit the main configuration file with your text editor.

sudo nano /etc/opendmarc.conf

Find the following line:

# 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.

TrustedAuthservIDs mail.yourdomain.com

Then find the following line.

# IgnoreAuthenticatedClients false

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

Then find this line:

# 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

Find the following line.

# 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 To: 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.

sudo systemctl restart opendmarc

Integrate OpenDMARC with Postfix SMTP Server

Edit the Postfix main configuration file.

sudo nano /etc/postfix/main.cf

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 file 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.

sudo systemctl restart postfix

Testing OpenDMARC Verification

Now send an email from your other email address to your domain address. After that, check the email headers. If OpenDMARC is working correctly, you can see the DMARC verification results like below.

Authentication-Results: OpenDMARC; dmarc=pass (p=none dis=none) header.from=gmail.com

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.

sudo nano /var/log/maillog

You will see something like below:

opendmarc[26495]: 61DAA3EA44: gmail.com pass

Testing OpenDMARC with Telnet

You can use telnet to spoof another domain name, such as paypal.com. First, run the following command to connect to port 25 of your mail server.

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 .
From:     [email protected]
To:       [email protected]
Subject:  Please update your password.

Click this link to update your password.
.
550 5.7.1 rejected by DMARC policy for paypal.com
quit

As you can see, my mail server rejected this email because it didn’t pass DMARC check and Paypal deployed a p=reject policy.

Note: If a domain’s DMARC policy is set to p=quarantine, then OpenDMARC milter will put the spoofed email into the Postifx hold queue indefinitely. The postmaster can list all messages in the queue with postqueue -p command and use the postsuper command line utility to release messages in hold queue.

Integrate Amavis with Postfix via Milter

As explained in the prerequisites section, I recommend switching from Amavis to OpenDKIM, but if you don’t like to switch, then you need to integrate Amavis with Postfix via the milter interface, so that OpenDMARC can read the DKIM verification result from Amavis.

Install the amavisd-milter package on CentOS/RHEL.

sudo dnf install amavisd-milter

Start the service.

sudo systemctl start amavisd-milter

Enable auto-start at boot time.

sudo systemctl enable amavisd-milter

Amavisd-milter listens on Unix socket at /run/amavisd/amavisd-milter.sock. Edit Postfix main configuration file.

sudo nano /etc/postfix/main.cf

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 the email 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.

sudo gpasswd -a postfix amavis

Restart Postfix for the changes to take effect.

sudo systemctl restart postfix

Now OpenDMARC will be able to read the DKIM verification result from Amavis.

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 🙂

Rate this tutorial

[Total: 0 Average: 0]