DKIM-Signierung mit OpenDKIM einrichten
Richte DKIM auf deinem Mailserver mit OpenDKIM ein. Erfahre, wie du Schlüsselpaare erstellst, Tabellen konfigurierst und OpenDKIM an Postfix anbindest.
Stand: Juli 2026
Zusammenfassung: Um E-Mails kryptografisch zu signieren, wird OpenDKIM als Milter an den MTA (wie Postfix) angebunden. Die Schlüsselgenerierung erfolgt über das Tool
opendkim-genkey. In OpenDKIM steuerst du die Zuordnung von Absendern zu Schlüsseln wahlweise über die DirektivenDomain,KeyFileundSelectoroder dynamisch überKeyTableundSigningTable.
Die Einrichtung von DKIM (DomainKeys Identified Mail) ist heute eine grundlegende Voraussetzung für eine gute E-Mail-Zustellbarkeit. Wenn dein Mailserver E-Mails unsigniert versendet, meldet Kuveris fehlende Signaturen. Mit OpenDKIM kannst du deine ausgehenden E-Mails automatisch signieren lassen.
Schlüssel generieren mit opendkim-genkey
Der erste Schritt besteht darin, ein kryptografisches Schlüsselpaar für deine Domain zu generieren. OpenDKIM bringt hierfür das Hilfswerkzeug opendkim-genkey mit.
Die Funktionsweise wird in den Handbüchern wie folgt beschrieben:
opendkim-genkey generates (1) a private key for signing messages using opendkim(8) and (2) a DNS TXT record suitable for inclusion in a zone file which publishes the matching public key for use by remote DKIM verifiers.
Um den Schlüssel zu erstellen, führst du das Werkzeug unter Angabe eines Selektors aus:
Run the script "opendkim-genkey -s SELECTOR". The opendkim-genkey man page has full details of options. This will generate a private key in PEM format and output a TXT record containing the matching public key appropriate for insertion into your DNS zone file.
Die Option -s definiert den Selektor:
Specifies the selector, or name, of the key pair generated. The default is "default".
Nach dem Ausführen des Befehls erhältst du zwei Dateien:
The filenames of these are based on the selector (see below); the private key will have a suffix of ".private" and the TXT record will have a suffix of ".txt".
Wenn du beispielsweise opendkim-genkey -s mail ausführst, werden die Dateien mail.private (der geheime Schlüssel, der sicher auf dem Server verbleiben muss) und mail.txt (enthält den öffentlichen DNS-Eintrag) angelegt.
Den öffentlichen Schlüssel im DNS veröffentlichen
Der in der .txt-Datei generierte Eintrag muss als TXT-Eintrag in der DNS-Zone deiner Domain eingepflegt werden.
Dazu gilt folgende Pfadvorgabe:
The public key DNS record should appear as a TXT resource record at: SELECTOR._domainkey.DOMAIN
Ein beispielhafter DNS-Eintrag sieht wie folgt aus:
v=DKIM1; t=y; p=MFwwDQYJ...AwEAAQ==
OpenDKIM konfigurieren (opendkim.conf)
In der Konfigurationsdatei /etc/opendkim.conf wird das Verhalten des Daemons definiert.
Betriebsmodus (Mode)
Die Option Mode bestimmt, ob OpenDKIM E-Mails signiert oder empfangene Signaturen prüft:
Selects operating modes. The string is a concatenation of characters that indicate which mode(s) of operation are desired. Valid modes are s (signer) and v (verifier). The default is sv
Setze den Wert beispielsweise auf:
Mode sv
Verbindungskanal (Socket)
Über die Option Socket kommuniziert der Mailserver (MTA) mit OpenDKIM:
Specifies the socket that should be established by the filter to receive connections from sendmail(8) in order to provide service. socketspec is in one of two forms: local:path, which creates a UNIX domain socket at the specified path, or inet:port[@host] or inet6:port[@host] which creates a TCP socket on the specified port and in the specified protocol family.
Beispiel für einen TCP-Socket auf Port 8891:
Socket inet:8891@localhost
Signier-Modus: Single-Domain vs. Multi-Domain
Beim Aktivieren des Signier-Modus müssen bestimmte Kombinationen von Direktiven gesetzt werden:
When signing mode is enabled, one of the following combinations must also be set: (a) Domain, KeyFile, Selector, no KeyTable, no SigningTable; (b) KeyTable, SigningTable, no Domain, no KeyFile, no Selector; (c) KeyTable, SetupPolicyScript, no Domain, no KeyFile, no Selector.
Kombination (a): Einzelne Domain (Single-Key)
Wenn du nur eine Domain signieren möchtest, reicht die einfache Konfiguration:
- Domain:
A set of domains whose mail should be signed by this filter. Mail from other domains will be verified rather than being signed. - KeyFile:
Gives the location of a PEM-formatted private key to be used for signing all messages. Ignored if a KeyTable is defined. - Selector:
Defines the name of the selector to be used when signing messages.
Beispiel:
Domain example.com
KeyFile /etc/dkimkeys/mail.private
Selector mail
Kombination (b): Mehrere Domains (KeyTable + SigningTable)
Für komplexere Mailserver, die E-Mails für mehrere Domains versenden, nutzt man Tabellen:
- KeyTable:
Gives the location of a file mapping key names to signing keys. If present, overrides any KeyFile setting in the configuration file. The data set named here maps each key name to three values: (a) the name of the domain to use in the signature’s "d=" value; (b) the name of the selector to use in the signature’s "s=" value; and (c) either a private key or a path to a file containing a private key. - SigningTable:
Defines a table used to select one or more signatures to apply to a message based on the address found in the From: header field. Keys in this table vary depending on the type of table used; values in this data set should include one field that contains a name found in the KeyTable (see above) that identifies which key should be used in generating the signature
Beispiel-Definition in opendkim.conf:
KeyTable refile:/etc/opendkim/KeyTable
SigningTable refile:/etc/opendkim/SigningTable
Starten des Daemons und Befehlszeilenoptionen
Beim manuellen Starten oder zur Kontrolle des Dienstes empfiehlt OpenDKIM folgende Parameter:
The current recommended set of command line options is: -l -p SOCKETSPEC -d DOMAIN -k KEYPATH -s SELECTOR
Integration in den MTA (Postfix-Anbindung)
Um OpenDKIM an Postfix anzubinden, musst du Postfix anweisen, diesen Milter für ein- und ausgehende E-Mails zu verwenden.
Füge dazu folgenden Konfigurationsblock in deine /etc/postfix/main.cf ein:
Add the following lines like this example to your postfix main.cf using your desired socket specification: smtpd_milters = inet:localhost:8891 non_smtpd_milters = inet:localhost:8891
Beispiel:
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
DNS-Eintrag prüfen (opendkim-testkey)
Nachdem du den DNS-Eintrag eingepflegt hast, kannst du mit dem Tool opendkim-testkey lokal prüfen, ob der im DNS veröffentlichte Schlüssel mit deinem privaten Schlüssel übereinstimmt und valide aufgelöst wird:
opendkim-testkey -d DOMAIN -s SELECTOR -k rsa.private
Zum Beispiel:
opendkim-testkey -d example.com -s mail -k /etc/dkimkeys/mail.private
Wenn dieser Befehl keine Fehler zurückgibt, ist deine Konfiguration bereit. Lade OpenDKIM und Postfix neu. Prüfe die ordnungsgemäße Funktion deiner ausgehenden DKIM-Signierung anschließend mit dem kostenlosen Kuveris-Scanner.
Weiterführende Links
- OpenDKIM Documentation and README (abgerufen: 18. Juli 2026)
- OpenDKIM Manual Page — opendkim.conf(5) (abgerufen: 18. Juli 2026)
- OpenDKIM Manual Page — opendkim-genkey(8) (abgerufen: 18. Juli 2026)