Guide to Install OpenDKIM for multiple domains with Postfix and Debian

This is a guide to installing OpenDKIM for multiple domains on a Postfix-installtion on Debian. I tried some other guides but kept running into problems, so this is how I did it.

Among others, Google Gmail and Yahoo mail check your email for a DKIM signature.

Install and Configure OpenDKIM

1. Install OpenDKIM

[code]apt-get install opendkim[/code]

Comment: This will install the latest available stable Debian packaged version of OpenDKIM which is currently 2.0.1. This version is already a couple of years old (2010).
If you know how/want to compile sources yourself, then the latest version is 2.4.3 (and 2.5.0 is right around the corner)

2. Edit the OpenDKIM config file

[code]nano /etc/opendkim.conf[/code]

Add these rows:

KeyTable /etc/opendkim/KeyTable
SigningTable /etc/opendkim/SigningTable
ExternalIgnoreList /etc/opendkim/TrustedHosts
InternalHosts /etc/opendkim/TrustedHosts

Note: If you run multiple instances of Postfix you need to add this to the opendkim.conf for each instance (or the ones you want to use opendkim)

3.  Edit /etc/opendkim/TrustedHosts

[code]nano /etc/opendkim/TrustedHosts[/code]

Add domains, hostnames and/or ip’s that should be handled by OpenDKIM. Don’t forget localhost.


4. Edit /etc/default/opendkim

[code]nano /etc/default/opendkim[/code]

Uncomment this row:

[code]SOCKET="inet:[email protected]" # listen on loopback on port 12345[/code]

Generate keys

Repeat these steps to generate keys for each domain you will send email from. Replace with your domain name in examples below.

1. Generate key

mkdir -p /etc/opendkim/keys/
cd /etc/opendkim/keys/
opendkim-genkey -r -d
chown opendkim:opendkim default.private

2. Add domain to KeyTable /etc/opendkim/KeyTable

[code]nano /etc/opendkim/KeyTable[/code]

Add line:


3. Add domain to SigningTable /etc/opendkim/SigningTable

[code]nano /etc/opendkim/SigningTable[/code]

Add line:


Note that in OpenDKIM 2.0.1 domain names are case sensitive (supposed to be fixed from 2.3.1 but I have not tested).
This means that in the above example an email from [email protected] will be signed, but an email from [email protected] will not be signed. The workaround is to add one extra entry for to SigningTable.

4. Add to DKIM public key to DNS

Add an entry for the public key to the DNS server you are using for your domain. You find the public key here:

[code]cat /etc/opendkim/keys/[/code]

Start OpenDKIM

[code]/etc/init.d/opendkim start[/code]

In the future, if you make any changes to configuration remember to restart: /etc/init.d/opendkim restart

Configure and Restart Postifx

1. Configure Postfix

[code]nano /etc/postfix/[/code]

Add or edit these lines:

milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:12345
non_smtpd_milters = inet:localhost:12345

2. Restart Postfix

[code]/etc/init.d/postfix reload[/code]

Or in my case as i run postfix multi instance:

[code]/etc/init.d/postfix-multi restart[/code]


Log files are in the /var/log directory

cat /var/log/mail.log
cat /var/log/mail.warn
cat /var/log/mail.err

Log more info

[code]nano /etc/opendkim.conf[/code]

Add this line:

[code]LogWhy yes[/code]


Guides that have helped me along the way: Debian Tutorials and Syslog