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


The 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 a 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 the 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 that makes your emails digitally signed.

But still, there are other features missing like using dovecot sieve rules to filter emails on the 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.

35 thoughts on “How to Install And Integrate DKIM With OpenDKIM And Postfix On a CentOS 6 VPS”

  1. Great tutorial!

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

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

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

    • You check that your emails are being authenticated and that your DNS records are properly set up using one of the following testing services:

      Send a signed email to

      Or, send a signed email to

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


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


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

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

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

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

    please how can i enable everything is pass

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

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

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

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

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


Leave a Comment

To prove you are human please solve the following *