As I couldn't find this exact tutorial in Stack, I share my findings with al of you. I always get things solved thanks to this comunity. Thanks!

Original question: I've read the tutorial posted by MountainX (https://askubuntu.com/questions/134725/setup-dkim-domainkeys-for-ubuntu-postfix-and-mailman), but I can't figure out how to apply these steps if I want to host and send e-mails for several domains. Does anybody have a clue?


Good! I figured this out from the post mentioned in the question. I made a kind of mix between the answer itself and the links provided in it. Specially the fourth link is the one I used.

So the thing goes like this. Suppose you've got a server or VPS and make one of your domains to be the main domain and be used as the server name (in my example: mydomain.com).

So, firts of all, we'll change to root to make things easier, but you can skip this step and use sudo befor every command.

sudo su

Now, we install OpenDKIM:

apt-get install opendkim opendkim-tools

Lets fix the configuration file. We're opening /etc/opendkim.conf for edition. I use nano, but it's the same with other editor.

nano /etc/opendkim.conf

Once opened, make it look like this. If you feel comfortable, you can change some options, but the Domain, KeyFile and Selector must remain commented.

# This is a basic configuration that can easily be adapted to suit a standard
# installation. For more advanced options, see opendkim.conf(5) and/or
# /usr/share/doc/opendkim/examples/opendkim.conf.sample.
#Domain                  example.com
#KeyFile                 /etc/opendkim/201205.private
#Selector                201205
# Commonly-used options
Canonicalization        relaxed/simple
Mode                    sv
SubDomains              yes
# Log to syslog
Syslog                  yes
LogWhy                  yes
# Required to use local socket with MTAs that access the socket as a non-
# privileged user (e.g. Postfix)
UMask                   022
UserID                  opendkim:opendkim
KeyTable                /etc/opendkim/KeyTable
SigningTable            /etc/opendkim/SigningTable
ExternalIgnoreList      /etc/opendkim/TrustedHosts
InternalHosts           /etc/opendkim/TrustedHosts
Socket                  inet:8891@localhost

Next, we create some of the folder and files that will hold information about what should OpenDKIM use and process. For now, the TrustedHosts file. We create and edit it:

mkdir /etc/opendkim
nano /etc/opendkim/TrustedHosts

We must put into this file a list of trusted addresses: localhost and, and your server name and IP:

Now we edit OpenDKIM config file.

nano /etc/default/opendkim

And add these lines at the end of the file. They'll tell OpenDKIM in which port it should expect signing requests:

SOCKET="inet:8891@localhost" # listen on loopback on port 8891

We open Postfix config file.

nano /etc/postfix/main.cf

And add these lines to the end of the file. They'll tell Postfix that it should send e-mails to be signed and where.

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

If you're not adding domains right now, you can restart everything, so the configuration takes effetc.

/etc/init.d/opendkim restart
/etc/init.d/postfix reload
/etc/init.d/postfix restart

Done! The server is ready to work with DKIM. Now, you need to add your domains to this system. The following process is the same for all the domains you want to add. I'll use otherdomain.com for the example, rplace it with your own.

Remember I was root from before, but if you're not, run sudo su or precede your commands with the keyword sudo.

sudo su

First, we create a directory for our domain and go inside of it:

mkdir -p /etc/opendkim/keys/otherdomain.com
cd /etc/opendkim/keys/otherdomain.com

Now we generate a key for the domain:

opendkim-genkey -r -d otherdomain.com

We give OpenDKIM user the ownership of the newly created file:

chown opendkim:opendkim default.private

And we open the KeyTable file to add our new key for our new domain:

nano /etc/opendkim/KeyTable

We add to the end of the file (after all other domains we may have here):

default._domainkey.otherdomain.com otherdomain.com:default:/etc/opendkim/keys/otherdomain.com/default.private

We open the SigningTable file.

nano /etc/opendkim/SigningTable

And append at the end of the file (again, we'll have one line for each domain):

otherdomain.com default._domainkey.otherdomain.com

I'm not sure of the necessity to do the next step, but I just did it, just in case... We open the TrustedHosts file.

nano /etc/opendkim/TrustedHosts

And add at the end of the file:


One last thing: we show the contents of the file /etc/opendkim/keys/otherdomain.com/default.txt.

cat /etc/opendkim/keys/otherdomain.com/default.txt

And add the information between the quotes to a TXT record in the DNS Zone of the domain, and we must also use default._domainkey as the name of the record. NOTE: "between the quotes" is the text that starts with "v=DKIM1;k=rsa; p=WIGfM...".

If we're done adding domains (by now), we restart everything to apply the cnages.

/etc/init.d/opendkim restart
/etc/init.d/postfix reload
/etc/init.d/postfix restart


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.