LLI Wiki — My Digital Knowledge Base

Check a DKIM record with dig and drill

Find the DKIM selector in an e-mail header and check the public key published in DNS.

DKIM (DomainKeys Identified Mail) signs outgoing e-mails; the receiver verifies the signature with a public key published in DNS. This article shows how to find the selector in a message header and check the published key.

1. Read the message header

Display the full headers of the received message (for example with the MxToolbox header analyzer) and find the DKIM-Signature field. The s= tag gives the selector, the d= tag the domain:

DKIM-Signature: ... d=contoso.com; s=selector2-contoso-com; ...

2. Get the public key from DNS

The TXT record lives at <selector>._domainkey.<domain>:

dig selector2-contoso-com._domainkey.contoso.com txt +short
drill selector2-contoso-com._domainkey.contoso.com txt

For a custom selector:

dig selector1._domainkey.example.com txt +short
drill selector1._domainkey.example.com txt

The answer looks like this (key truncated):

"v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQ..."

The p= tag holds the Base64 public key.

3. Validate the setup

Useful DNS commands

# All records of a domain
dig +nocmd example.com any +multiline +noall +answer

# Query a name server directly
dig google.com ANY @ns1.google.com

# Same with drill
drill -t txt example.com

# Reverse lookup
dig -x 192.0.2.10
Mastodon LLIMastodon SocialFosstodon