How to install and integrate DKIM with OpenDKIM and Postfix on a CentOS 6 VPS

This tutorial is part 5 of the mailserver set-up with virtual users and domains using Postfix and Dovecot series. It goes through the steps of installing and integrating OpenDKIM in Postfix on a CentOS 6 Linux VPS.

After completing this tutorial you will end-up having OpenDKIM adding digital signatures to your emails, thus making the mailserver set-up even more robust and professional.

Also, learn how to do this on a Debian Squeeze Linux VPS: Install and Configure openDKIM on Debian Squeeze.

What is OpenDKIM?
It is a digital email signing/verification technology, which is already supported by some common mail providers. In general, DKIM means digitally signing all messages on the mail-server to verify the message was actually sent from the domain in question and was not spam


Before going any further, make sure you’re in a screen session and your system is fully up-to-date by running:

## screen -U -S opendkim-screen
## yum update


OpenDKIM is available in the EPEL repository, so we need to enable it on the system before we can install OpenDKIM

## wget -P /tmp http://mirror.pnl.gov/epel/6/i386/epel-release-6-8.noarch.rpm
## rpm -Uvh /tmp/epel-release-6-8.noarch.rpm
## rm -f /tmp/epel-release-6-8.noarch.rpm


Install the package using yum:

## yum install opendkim


Next thing to do is to configure OpenDKIM. Its main configuration file is located in /etc/opendkim.conf, so before making any changes create a backup and add/edit the following:

## cp /etc/opendkim.conf{,.orig}
## vim /etc/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


Generate set of keys for your mydomain.com domain name:

## mkdir /etc/opendkim/keys/mydomain.com
## opendkim-genkey -D /etc/opendkim/keys/mydomain.com/ -d mydomain.com -s default
## chown -R opendkim: /etc/opendkim/keys/mydomain.com
## mv /etc/opendkim/keys/mydomain.com/default.private /etc/opendkim/keys/mydomain.com/default

add mydomain.com to OpenDKIM’s key table by adding the following record in /etc/opendkim/KeyTable

default._domainkey.mydomain.com mydomain.com:default:/etc/opendkim/keys/mydomain.com/default

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

*@mydomain.com default._domainkey.mydomain.com

and add your domain and your hostname as trusted hosts in /etc/opendkim/TrustedHosts:

assuming the domain in question is ‘mydomain.com’ and server’s hostname is set to ‘host.mydomain.com’

finally, edit your mydomain.com DNS zone and add the TXT record from /etc/opendkim/keys/mydomain.com/default.txt

default._domainkey      IN      TXT     ( "v=DKIM1; k=rsa; "
          "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDApHRr7ZmXRaAB+RQRbP4VdMwIrIHIP18KFtXRsv/xpWc0Gix6ZXN13fcG03KNGKZo2PY+csPkGC5quDnH5V0JEhDZ78KcDWFsU6u4fr9ktVAdt6P7jWXjcyqdHOZ8+YN4cAeU4lRFNgQvdupIcByYwzPYMgBFHfJm9014HvRqhwIDAQAB" )  ; ----- DKIM key default for mydomain.com

it is also a good idea to add an SPF record if you haven’t already

mydomain.com. 14400 IN TXT "v=spf1 a mx ~all"

you can verify your dkim TXT record is valid using dig for example:

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

"v=DKIM1\; k=rsa\; " "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDApHRr7ZmXRaAB+RQRbP4VdMwIrIHIP18KFtXRsv/xpWc0Gix6ZXN13fcG03KNGKZo2PY+csPkGC5quDnH5V0JEhDZ78KcDWFsU6u4fr9ktVAdt6P7jWXjcyqdHOZ8+YN4cAeU4lRFNgQvdupIcByYwzPYMgBFHfJm9014HvRqhwIDAQAB"


In order to integrate OpenDKIM with Postfix we need to add the following few lines in /etc/postfix/main.cf:

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


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

## service opendkim start
## chkconfig opendkim on
## service postfix restart


To test the set-up simply send an email to check-auth@verifier.port25.com 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

Implementing OpenDKIM to the mailserver set-up with virtual users and domains using Postfix and Dovecot adds another nice feature which makes your emails digitally signed.

But still, there are other features missing like using dovecot sieve rules to filter emails on server-side, scanning emails for viruses etc.. In the next few related articles, we will be adding additional features to the set-up so stay tuned.

Update: Part 6 – How to set-up server-side email filtering with Dovecot Sieve and Roundcube on a CentOS 6 VPS

Of course, if you are one of our Linux VPS Hosting customers, you don’t have to do any of this, simply ask our admins, sit back and relax. Our admins will set this up for you immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

View Comments (31)

  • hello.
    I installed a new mail server according to your instructions. but SquirrelMail does not receive mail. Can you show me how to solve this problem?
    thank you very much!

  • i did all the things as said but when see email header which received from server it does not show DKIM value
    Will Be Glad if Any one Can Help

    • Did you follow the instructions closely?

      Please check your mail server log files for error messages related to DKIM or so.

  • SPF check: pass
    DomainKeys check: neutral
    DKIM check: neutral
    Sender-ID check: pass
    SpamAssassin check: ham

    please how can i enable everything is pass

  • ----------------------------------------------------------
    DKIM check details:
    Result: fail (signature doesn't verify)
    ID(s) verified:
    Canonicalized Headers:

    Canonicalized Body:

    DNS record(s):
    default._domainkey.multihome.com. 86024 IN TXT "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCl+bUxiRBLFqU6yyfkCLQJNlaJxhknhceeXTIxXO1lsTMZHrpddrGSqITgqjY0LzYjUAMvV66vAolgrRTckn8z98+PJI4xXsrMOoi6tjCBem4O+FnVCvGNWRpy7JThxTe2gkUEvTuQ+r0IglaGSfpvmci2IQNaj642bmg5JKgmmQIDAQAB;"

    Public key used for verification: default._domainkey.multihome.com(1024 bits)

    NOTE: DKIM checking has been performed based on the latest DKIM specs
    (RFC 4871 or draft-ietf-dkim-base-10) and verification may fail for
    older versions. If you are using Port25's PowerMTA, you need to use
    version 3.2r11 or later to get a compatible version of DKIM.

    • There is no DNS record found for default._domainkey.multihome.com. Please follow the instructions closely to install and integrate DKIM.

  • Hi,

    They are all working: SPF, DKIM, DMARC, DomainKeys and passes all the post25 tests but emails are delivered in SPAM folder only in Gmail.
    Here are the headers:
    Delivered-To: testpds2@gmail.com
    Received: by with SMTP id yf7csp377905wjb;
    Thu, 10 Dec 2015 01:15:52 -0800 (PST)
    X-Received: by with SMTP id 203mr41790134wme.89.1449738952207;
    Thu, 10 Dec 2015 01:15:52 -0800 (PST)
    Received: from s17772156.onlinehome-server.info (s17772156.onlinehome-server.info. [])
    by mx.google.com with ESMTPS id v10si17523219wjx.223.2015.
    (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
    Thu, 10 Dec 2015 01:15:52 -0800 (PST)
    Received-SPF: pass (google.com: domain of info@pixeldraw.net designates as permitted sender) client-ip=;
    Authentication-Results: mx.google.com;
    spf=pass (google.com: domain of info@pixeldraw.net designates as permitted sender) smtp.mailfrom=info@pixeldraw.net;
    dkim=pass header.i=@pixeldraw.net;
    dmarc=pass (p=QUARANTINE dis=NONE) header.from=pixeldraw.net
    Received: from webmail.pixeldraw.net (s17772156.onlinehome-server.info [])
    by s17772156.onlinehome-server.info (Postfix) with ESMTPA id 933451FED
    for ; Thu, 10 Dec 2015 10:15:51 +0100 (CET)
    DKIM-Filter: OpenDKIM Filter v2.10.3 s17772156.onlinehome-server.info 933451FED
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pixeldraw.net;
    s=mail; t=1449738951;
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8;
    Content-Transfer-Encoding: 8bit

    I think the problem is: "Received: from webmail.pixeldraw.net (s17772156.onlinehome-server.info [])
    by s17772156.onlinehome-server.info (Postfix) with ESMTPA id 933451FED"

    Thanks in advance

  • Hello,
    I am having some trouble. Please help if there are anyone. I've configured everything just like this. Dkim is working fine if I send email with roundcube webmail. But if I use any external email software then it doesn't show any dkim record. Can anyone help me?

    • That's because your external email client uses your IP to send mail through your SMTP server and an entry needs to be added for your IP or IP range(if your IP is dynamic) in /etc/opendkim/TrustedHosts.

    • Did you setup plublic/private keys for example.co and add the domain to the OpenDKIM’s configuration files ?

  • Hi.

    Thanks for your great tutorial. I made all the things (I think I did this quite correctly) but, when I send a mail to auth-results, here is the answer

    SPF check: pass
    DKIM check: none
    SpamAssassin check: ham

    This might be bad for me as no DKIM was found? Ham for SpamAssassin = I'm a spammer, right? What is my mistake? Thanks for the help.

    • Hi Thibaut,

      Our tutorial is tested and it is working without a problem. Please make sure that you closely followed the steps and updated all paths, domains, usernames, etc... accordingly.

      • I have some problems to configure the domain I think. The webmail works (but no DKIM) but I can't use Thunderbird to send mails, only IMAP is working... It might be the origin of the problems.

  • I have problem not authenticated but DKIM verification successful and no signing table match but DKIM verification successful