Skip to content

Instantly share code, notes, and snippets.

@user890104
Created July 31, 2018 12:10
Show Gist options
  • Save user890104/00a9bf460b11cb92c09fc5fc146c402a to your computer and use it in GitHub Desktop.
Save user890104/00a9bf460b11cb92c09fc5fc146c402a to your computer and use it in GitHub Desktop.
Certbot / Letsencrypt Wildcard DNS with nsupdate hook
# This will issue a production (valid and trusted) certificate
certbot certonly --agree-tos --manual --preferred-challenge=dns --manual-auth-hook=./hook.sh --register-unsafely-without-email --manual-public-ip-logging-ok -d '*.example.com' -d 'example.com' --server https://acme-v02.api.letsencrypt.org/directory
# This will issue a test certificate
certbot certonly --agree-tos --manual --preferred-challenge=dns --manual-auth-hook=./hook.sh --register-unsafely-without-email --manual-public-ip-logging-ok -d '*.example.com' -d 'example.com' --server https://acme-staging-v02.api.letsencrypt.org/directory
#!/bin/bash
DNS_SERVER='ns1.example.com'
DNS_ZONE='example.com'
if [ -z "$CERTBOT_DOMAIN" ]
then
echo 'Empty $CERTBOT_DOMAIN provided'
exit 1
fi
if [ -z "$CERTBOT_VALIDATION" ]
then
echo 'Empty $CERTBOT_VALIDATION provided'
exit 1
fi
HOST='_acme-challenge'
echo 'Domain: '"${CERTBOT_DOMAIN}"
echo 'Validation: '"${CERTBOT_VALIDATION}"
echo 'Sending to DNS server...'
nsupdate << EOM
server ${DNS_SERVER}
zone ${DNS_ZONE}
update delete ${HOST}.${CERTBOT_DOMAIN} A
update add ${HOST}.${CERTBOT_DOMAIN} 300 TXT "${CERTBOT_VALIDATION}"
send
EOM
echo 'Waiting 5 seconds...'
sleep 5
echo 'Record should be set, returning to Certbot'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment