Wednesday, February 16, 2022

Solved Error: configure DNS BIND for DKIM: opendkim-testkey: key not found

Problem

Whenever you try to install dkim and Postfix without cpanel, you have to face the error on configuring DNS record (BIND):

opendkim-testkey: key not found

or 

opendkim-testkey: unknown key

Solution

to cut long story short, to store the longer text on a DNS record (i.e Bind9 or Bind), we need to split the data into rows with brackets "( ... )" and quotes ("...") and store it sequentially on different lines. The notation makes me more confusing, just let's see in the example:

default._domainkey      IN      TXT     ("v=DKIM1; h=sha256; k=rsa;"
"p=HalfOfTheKeyHereHalfOfTheKeyHereHalfOfTheKeyHere"
"andAnotherHalfHereAnotherHalfHereAnotherHalfHereAnother")

this key is using 3 consecutive lines.

Testing

you can directly test the configuration from DKIM

opendkim-testkey -d your-domain-name -s default -vvv

this will show that the OK result.

Additional 

you can check the consistency of DNS using this command, please change your-domain-name with your appropriate domain name or as your settings on bind dns zones

named-checkzone default._domainkey.your-domain-name db.your-domain-name