How To Install OpenDKIM With Postfix On CentOS

Article By: jimmy


postfix OpenDKIM on a BIP media VPS Server

Postfix OpenDKIM will give Your mail a signature that will eventually lower the spam score of the mail coming from your domain. This will help significantly to exclude these mails from being considered as spam by other servers, including google (google “accidentally” often considers a clean mail as spam because it has no dkim signature).

On a Centos box, install OpenDKIM first. It comes from the Epel repos, so if you don’t have them listen in Your repo list, install it 1st:
wget -P /tmp
rpm -Uvh /tmp/epel-release-6-8.noarch.rpm
yum install opendkim

Next, the configuration file that we will be using is below. Either find/add those options to the original config file, or even better, make a copy of the original file and replace /etc/opendkim.conf with the following:
AutoRestart             Yes
AutoRestartRate         10/1h
LogWhy                  Yes
Syslog                  Yes
SyslogSuccess           Yes
Mode                    s
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:[email protected]
PidFile                 /var/run/opendkim/
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

Now we have to setup the public and private keys (replace yourdomain in the text with the apropriate domain name):
mkdir /etc/opendkim/keys/yourdomain
opendkim-genkey -D /etc/opendkim/keys/yourdomain/ -d yourdomain -s default
chown -R opendkim: /etc/opendkim/keys/yourdomain
mv /etc/opendkim/keys/yourdomain/default.private /etc/opendkim/keys/yourdomain/default

Now we have to add it to the OpenDKIM keytable. Edit /etc/opendkim/KeyTable and add:
default._domainkey.yourdomain yourdomain:default:/etc/opendkim/keys/yourdomain/default

Next step, adding the domain to the signing table. Edit /etc/opendkim/SigningTable, and insert:

And the last move with DKIM, edit /etc/opendkim/TrustedHosts and add your LAN there.

Now we have to tell Postfix that we want to use OpenDKIM miltering. Edit /etc/postfix/ and insert at the end of the file:
smtpd_milters           = inet:
non_smtpd_milters       = $smtpd_milters
milter_default_action   = accept
milter_protocol         = 2

Now we can try to start OpenDKIM and reload postfix:
service opendkim start
chkconfig opendkim on
service postfix reload

If everything worked well, You can send a test mail and see in the source and it contains a DKIM signature, tail /var/log/maillog -f and see the OpenDKIM entries like DKIM-Signature field added (s=default, d=yourdomain)

Now you should add the dkim signature to your domain file (probably at your ISP). The exact signature as it should look was generated by the opendkim certificate generator, and it is located in /etc/opendkim/keys/yourdomain/default.txt

So, all you need is to insert it in the DNS zone file or send it to Your ISP if the DNS is hosted and after a while it will start to work. If you want to check if the DKIM signature is properly inserted in your DNS zone, you can do dig +short default._domainkey.yourdomain TXT and it should give You and answer with the hashed key.

Tags: , , ,

Welcome to the healthcare-only HIPAA - GDPR compliant cloud. Exclusively hosted on a HPC environment!

Learn more or start today by choosing your secure HIPAA - GDPR compliant server's Operating System bellow and pick the package that's best for you.

BIPmd makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine, thousand or more.

Windows VPS options and add ons
Linux VPS options and add ons


Looking for a custom solution?

Our technicians can provide you with the best custom-made solutionss on the market, no matter whether you're a small business or large enterprise.

Get in touch

Leave a Reply