Script to update DKIM entries in a BIND zone file
Find a file
2024-10-01 19:00:42 -07:00
2021-08-11 initial commit 2024-10-01 19:00:42 -07:00
test initial commit 2024-10-01 19:00:42 -07:00
README.md initial commit 2024-10-01 19:00:42 -07:00
update-dkim.py initial commit 2024-10-01 19:00:42 -07:00

Script to update DKIM entry in BIND zone file

This script takes two arguments:

  1. a BIND DNS zone file
  2. a DNS record generated by 'opendkim-genkey'

opendkim-genkey is part of the opendkim-tools Debian package

This script use regex to

  1. extract the DKIM selector and the value of the TXT record from the DKIM TXT record generated by opendkim-genkey
  2. replace the DKIM selector and TXT value in the zone file with the new values

Example

  • generate a new DKIM key for mail.example.org
  • remember to increase the increment if generating a new key on the same date
INCREMENT=1; /usr/sbin/opendkim-genkey -b 2048 -d mail -s $(/bin/date +%Y%m%d)-$INCREMENT

# generate a DNS DKIM TXT record such as '20210811-1.txt'
/usr/sbin/opendkim-genkey -b 2048 -d example.org -s $(/bin/date +%Y%m%d)-1

Then run this update-dkim.py, passing the zone file you want to update and the above .txt file:

update-dkim.py <zone file> 20210811-1.txt