Table of Contents

Install and integrate DKIM with OpenDKIM and Postfix on a CentOS

In this article we are going to see  the steps of installing and configuring dkim with OpenDKIM  on a CentOS 7. I am showing some easy steps with pictures as well video tutorial tutorial to install and configure OpenDKIM. Lets learn something about OpenDKIM

What is OpenDKIM ?

OpenDKIM is an open source implementation of the DKIM (Domain Keys Identified Mail) sender authentication system which is an email validation system designed to detect email spoofing by providing a mechanism to allow receiving mail exchangers to check that incoming mail from a domain is authorized by that domain’s administrators. A digital signature included with the message can be validated by the recipient using the signer’s public key published in the DNS.

Steps to Install OpenDKIM

1. Update system and install required packages

# sudo yum update -y

# yum install curl wget vim openssl man

 

2. Enable EPEL Repository

OpenDKIM is available in EPEL ( Extra Packages for Enterprise Linux ) Repository. EPEL Repository can enable with this command

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

We can check this repository is enabled in system by the following command

# yum repolist

 

3. Once you came to know EPEL Repository is enabled go ahead and install OpenDKIM

# yum install opendkim

 

4. Rename its default config file in etc/opendkim/ and proceed with adding new OpenDKIM Config file in the same directory with

# mv /etc/opendkim.conf{,.default}

# vi /etc/opendkim.conf

 

5. Adding below configuration in new opendkim.conf

AutoRestart Yes
AutoRestartRate 10/1h
LogWhy Yes
Syslog Yes
SyslogSuccess Yes
Mode sv
Canonicalization relaxed/simple
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts
KeyTable refile:/etc/opendkim/KeyTable
SigningTable refile:/etc/opendkim/SigningTable
SignatureAlgorithm rsa-sha256
Socket inet:8891@localhost
PidFile /var/run/opendkim/opendkim.pid
UMask 022
UserID opendkim:opendkim
TemporaryDirectory /var/tmp

Configure Public / Private Keys

1. Generate keys for your Domain by the following commands

# mkdir /etc/opendkim/keys/testmail.in

# opendkim-genkey -D /etc/opendkim/keys/testmail.in/ -d testmail.in -s default

# chown -R opendkim: /etc/opendkim/keys/testmail.in

# mv /etc/opendkim/keys/testmail.in/default.private /etc/opendkim/keys/testmail.in/default

 

2. Once the key is generated successfully, add your domain in the following records

Edit  /etc/opendkim/KeyTable and add your domain name

default._domainkey.testmail.in testmail.in:default:/etc/opendkim/keys/testmail.in/default

 

3. next, edit /etc/opendkim/SigningTable and add the following record to OpenDKIM’s signing table

*@testmail.in default._domainkey.testmail.in

 

4. also add your domain and your hostname as trusted hosts in /etc/opendkim/TrustedHosts

127.0.0.1
testmail.in
mta.testmail.in

 

5. Start OpenDKIM and Enable the service on boot

# sudo systemctl start opendkim.service

# sudo systemctl enable opendkim.service

 

6. finally, edit your testmail.in DNS zone and add the TXT record from /etc/opendkim/keys/testmail.in/default.txt also

 

 

7. You should add an SPF record if you haven’t already

testmail.in. 14400 IN TXT “v=spf1 a mx ~all

 

8. Verify your dkim TXT record is valid using dig for example

# dig +short default._domainkey.mydomain.com TXT

Configure Postfix

1. To integrate OpenDKIM with Postfix we need to add the following few lines in /etc/postfix/main.cf

smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept
milter_protocol = 2

 

2. Finally, Restart Services

Add OpenDKIM to your system’s start-up and start opendkim and restart postfix using the following commands:

# systemctl restart opendkim.service

# systemctl restart postfix.service

Test The Setup

To test the set-up simply send an email to [email protected] and you should receive back an email containing something like this:

==========================================================
Summary of Results
==========================================================
SPF check: pass
DomainKeys check: neutral
DKIM check: pass
DKIM check: pass

Video Tutorial

47 thoughts on “Install and integrate DKIM with OpenDKIM and Postfix on a CentOS

  1. Helpful info. Lucky me I discovered your website accidentally, and I am surprised why this twist of fate did not took place earlier! I bookmarked it. Sibylle Jud Adamec

  2. When some one searches for his vital thing, so he/she desires to be available that in detail, so that thing is maintained over here. Amara Wilburt Anatole

  3. Very couple of web sites that transpire to become detailed beneath, from our point of view are undoubtedly properly worth checking out. Waneta Korey Kienan

  4. Simply desire to say your article is as astounding. The clarity for your post is just great and that i
    can think you are knowledgeable in this subject. Well with your permission allow
    me to grab your RSS feed to keep updated with approaching post.
    Thank you 1,000,000 and please keep up the gratifying work.

  5. Hello,

    I followed the complete steps but I’m not able to get my emails DKIM signed..here is the result –

    Thank you for using the verifier,

    The Port25 Solutions, Inc. team

    ==========================================================
    Summary of Results
    ==========================================================
    SPF check: pass
    “iprev” check: pass
    DKIM check: none

Leave a Reply

Your email address will not be published. Required fields are marked *