Skip to content

Instantly share code, notes, and snippets.

@markizano
Created April 29, 2024 02:02
Show Gist options
  • Save markizano/a4aac9d29d2b2f1786e10c1f5c528732 to your computer and use it in GitHub Desktop.
Save markizano/a4aac9d29d2b2f1786e10c1f5c528732 to your computer and use it in GitHub Desktop.
Signs dnssec security keys so our DNS records are always signed.
#!/bin/bash
# Source: https://www.digitalocean.com/community/tutorials/how-to-setup-dnssec-on-an-authoritative-bind-dns-server--2
DOMAIN="$1"
PKIDIR="${PKIDIR:-/etc/bind/pki}"
ZONEDIR="${ZONEDIR:-/etc/bind/kizano}"
DOMAIN_KEY=""
# Set domain key in a config file under protected permissions.
test -s /etc/default/dnssec && . /etc/default/dnssec
die() { echo $@; exit 8; }
test -z "$DOMAIN" && die "Usage: $0 [domain]"
echo "$DOMAIN" | grep -qiP '^--?h(elp)?' && die "Usage: $0 [domain]"
set -e
test -d "$PKIDIR" || mkdir -p "$PKIDIR"
(
cd $PKIDIR
dnssec-keygen -a ${DOMAIN_KEY} -b 4096 -n ZONE "$DOMAIN"
dnssec-keygen -f KSK -a ${DOMAIN_KEY} -b 4096 -n ZONE "$DOMAIN"
)
dnssec-signzone -3 "`tr -dc '0-9a-f' </dev/urandom | head -c32`" -A -N INCREMENT \
-o "$DOMAIN" -S -K $PKIDIR -t "$ZONEDIR/$DOMAIN"
echo -e "You will need to set these with your domain registrar:\n$(<dsset-$DOMAIN.)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment