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

how-to-install-and-integrate-opendkim-with-postfix-on-a-centos-6-vpsThis 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
## 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/
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp


Generate set of keys for your domain name:

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

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

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


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

assuming the domain in question is ‘’ and server’s hostname is set to ‘’

finally, edit your DNS zone and add the TXT record from /etc/opendkim/keys/

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

it is also a good idea to add an SPF record if you haven’t already 14400 IN TXT "v=spf1 a mx ~all"

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

## dig +short 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/

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

How to install Suhosin on a Linux VPS
Install October CMS on an Ubuntu VPS with Nginx and MariaDB
How to Use Logrotate to Manage Logs on Ubuntu
  • Pablo B

    Pablo BPablo B

    Author Reply

    Great tutorial!

    But.. just a question about the test. How can be possible that dkim appears as passed, but DomainKeys check appears as neutral?

  • admin


    Author Reply

    DomainKeys are not the same as DKIM, although very similar.

  • Steve B.

    Steve B.Steve B.

    Author Reply

    One of the most thorough installation walkthroughs I have ever seen; nothing was left to chance with your instructions. Thanks! You guys should set up a wiki with this and other stuff…

  • Lucas


    Author Reply

    First of all, thank you for your walkthrough

    I use Godaddy to change my DNS ZoneFile, and even though I followed your walkthrough I still got a failed result for DKIM saying that the signature could not be verified. Any ideas how I could possibly fix that?

  • Hendra S.

    Hendra S.Hendra S.

    Author Reply

    Great tutorial, thanks!

  • Fxbalacon


    Author Reply

    Great tutorial, thanks!

    But I want to ask you is how to configure DomainKeys check: pass

    • admin


      Author Reply

      Hi Fxbalacon,

      may we ask why you need DomainKeys if you have DKIM working?

      DomainKeys Identified Mail (DKIM) is the successor to Yahoo’s DomainKeys. They are quite similar in functionality, except that DKIM has additionally adopted aspects from additional Mail Standards, it is more flexible and secure, it supports multiple signature algorithms (as opposed to just one available with DomainKeys), it has the ability to support signature timeouts in DNS and a few more useful options…

      So, you don’t really need DomainKeys if you have DKIM set-up on your mail server.


  • Kaloyan


    Author Reply

    finally, edit your DNS zone and add the TXT record from /etc/opendkim/keys/


    • admin


      Author Reply

      Each domain have authoritative DNS servers that publish information about that domain. You may use the ‘host -t ns’ command to identify the DNS servers responsible (authoritative) for your domain’s zone file.

      If you didn’t change the authoritative name servers for your domain at your domain registrar at the time of registration or later any time, most likely you use your domain registrar’s name servers so you can create a new TXT domain record for your domain via your domain registrar. Log in to your domain registrar, find the ‘DNS Zone Editor’ (or the section where you can create a DNS record) and create a new TXT DNS record.

      If you use custom name servers for your domain, you need to edit the DNS zone file hosted at your name servers.

  • henho


    Author Reply

    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!

    • admin


      Author Reply

      Did you check your mail server log files?

  • Rahul


    Author Reply

    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

    • admin


      Author Reply

      Did you follow the instructions closely?

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

  • Adrian


    Author Reply

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

    please how can i enable everything is pass

  • UGUR


    Author Reply

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

    Canonicalized Body:

    DNS record(s): 86024 IN TXT “p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCl+bUxiRBLFqU6yyfkCLQJNlaJxhknhceeXTIxXO1lsTMZHrpddrGSqITgqjY0LzYjUAMvV66vAolgrRTckn8z98+PJI4xXsrMOoi6tjCBem4O+FnVCvGNWRpy7JThxTe2gkUEvTuQ+r0IglaGSfpvmci2IQNaj642bmg5JKgmmQIDAQAB;”

    Public key used for verification: 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.

    • admin


      Author Reply

      There is no DNS record found for Please follow the instructions closely to install and integrate DKIM.

  • Eugen


    Author Reply


    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:
    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 ( [])
    by 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 ( domain of designates as permitted sender) client-ip=;
    spf=pass ( domain of designates as permitted sender);
    dmarc=pass (p=QUARANTINE dis=NONE)
    Received: from ( [])
    by (Postfix) with ESMTPA id 933451FED
    for ; Thu, 10 Dec 2015 10:15:51 +0100 (CET)
    DKIM-Filter: OpenDKIM Filter v2.10.3 933451FED
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;;
    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 ( [])
    by (Postfix) with ESMTPA id 933451FED”

    Thanks in advance

    • admin


      Author Reply

      Please run:
      cat /etc/hosts

      and provide us with the output.

  • Summer Joe

    Summer JoeSummer Joe

    Author Reply

    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?

    • admin


      Author Reply

      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.

  • suman


    Author Reply

    no signing table match for

    Having this error

    • admin


      Author Reply

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

Free Migration to RoseHosting. Award Winning Linux VPS Hosting with Fully Managed Support. Coupon RHBLOG50 for 50% offOrder Now