LetsEncrypt BIND DNS and ACME DNS-01 server setup guide
Are you looking to setup your own DNS server for LetsEncrypt's ACME DNS-01 verification challenges then this guide is for you. LetsEncrypt wild card certificates can also be requested using the same DNS records. I use Debian Linux so this guide is based on Debian 12 at the time of this writing.
Domain registrar DNS records setup
First add a new DNS record for your dns server, for example dns.example.com AAAA 2001:0db8:a55b:42df:5d01:2359:a67e:737d or / and dns.example.com A 203.0.113.9 A/AAAA record with your server IP where you will serve your BIND9 DNS server.
Now for each hostname create a NS record in your domain registrar, for example. NS _acme-challenge.example.com dns.example.com NS _acme-challenge.www.example.com dns.example.com NS _acme-challenge.server1.example.com dns.example.com NS _acme-challenge.server2.example.com dns.example.com NS _acme-challenge.server3.example.com dns.example.com
Server Setup
Install BIND9 DNS server apt install bind9 dnsutils
Now generate a TSIG key to update your DNS server tsig-keygen -a hmac-sha256 mainserver, I chose the key name mainserver as my primary key to get certificates for both my naked domain example.com and www.example.com. You can generate as many TSIG keys as you want for each of your servers, this is good because just in case one of your servers gets compromized then all you have to do is replace the key in your DNS server.
Now we start configuring the BIND9 server. This example includes four different servers (primary, server1, server2, server3) using the DNS server for generating LetsEncrypt certificates
Now configure named.conf.options file, replace the example IP with your own, for IPv4 use listen-on { 127.0.0.1; 203.0.113.9; };, I only use IPv6 so mine is set to listen-on-v6 { ::1; 2001:0db8:a55b:42df:5d01:2359:a67e:737d; };
Now create a new zone file listed above (/var/lib/bind/example.com.zone), replace the values accordingly.
Last line in this file must be a blank line.
Now check the zone file by running named-checkzone example.com. /var/lib/bind/example.com.zone
Now restart BIND server with your new settings systemctl restart bind9
Client server setup
Install apt install dnsutils
Now create a new file for each server you created above and paste the exact contant in the file, for example your primary client, create a new file in /root/tsig-acme.key
For each new server paste the content of key file you created above, server1, server2, server3 and so on.
Now open the terminal in your client server and run (export) these commands.
Now finally request the certificate using acme.sh
Let me know if you have any comments or if there is any error in this guide.