Intranet SSL Certificates Using Let’s Encrypt | DNS-01

Let's EncryptLet’s Encrypt is a great service offering the ability to generate free SSL certs.  The way it normally works is using http-01 challenge…  to respond to the Let’s Encrypt challenge the client (typically Certbot) puts an answer in the webroot.  Let’s Encrypt makes an http request and if it finds the response to the challenge it issues the cert.


Certbot is great for public web-servers.

Generating Intranet SSL Certs Using DNS-01 Challenge

But, what if you’re generating an SSL certificate for a mail server, or mumble server, or anything but a webserver?  You don’t want to spin up a web-server just for certificate verification.

Or what if you’re trying to generate an SSL certificate for an intranet server  Many homelabs, organizations and businesses need publicly signed SSL certs on internal servers.  You may not even want external A records for these services, much less a web-server for validation.

ACME DNS Challenge

Fortunately, Let’s Encrypt introduced the DNS-01 challenge in January of 2016.  Now you can respond to a challenge by creating a TXT record in DNS.

ACME Let's Encrypt DNS-01 Challenge Diagram


Lukas Schauer wrote dehydrated (formerly which can be used to automate the process.  If you need to generate SSL certs for Windows I’ve added the ability to output to PFX / PKCFS 12 in my fork.

Here’s a quick guide on Ubuntu 16.04, but it should work on any Linux distribution (or even FreeBSD).

Install dehydrated /

sudo su
mkdir /etc/dehydrated
cd /etc/dehydrated
mkdir certs accounts
cd /opt
git clone
cd dehydrated
cp docs/examples/config /etc/dehydrated/
cp docs/examples/domains.txt /etc/dehydrated
ln -s /opt/dehydrated/dehydrated /usr/local/bin/

Hook for DNS-01 Challenge

At this point, you need to install a hook for your DNS provider.  If your DNS provider doesn’t have a hook available you can write one against their API, or switch to a provider that has one.

If you need to pick a new provider with a proper API my favorite DNS Providers are CloudFlare and Amazon Route53.  CloudFlare is what I use for  It gets consistently low latency lookup times according to SolveDNS, and it’s free (I only use CloudFlare for DNS, I don’t use their proxy caching service which can be annoying for visitors from some regions).  Route53 is one of the most advanced DNS providers.  It’s not free but usually ends up cheaper than most other options and is extremely robust.  The access control, APIs, and advanced routing work great.  I’m sure there are other great DNS providers but I haven’t tried them.

Here’s how to set up a CloudFlare hook as an example:

cd /opt/
git clone
apt install python3 python3-pip
pip3 install -r letsencrypt-cloudflare-hook/requirements.txt

In letsencrypt-cloudflare-hook/ change the top line to point at python3:

#!/usr/bin/env python3

Config File

Edit the “/etc/dehydrated/config” file… add or uncomment the following lines:

[email protected]
export CF_EMAIL='[email protected]'
export CF_KEY='your_cloudflare_API_key'


Create an /etc/dehydrated/domains.txt file, something like this:

The first four lines will each generate their respective certificates, the last line creates a multi-domain or SAN (Subject Alternate Name) cert with multiple entries in a single SSL certificate.

Finally, run

dehydrated -c

The first time you run it, it should get the challenge from Let’s Encrypt, and provision a DNS TXT record with the response.  When validated the certs will be placed under the certs directory and from there you can distribute them to the appropriate applications.  The certificates will be valid for 90 days.

For subsequent runs will check to see if the certificates have less than 30 days left and attempt to renew them.


It would be wise to run dehydrated -c from cron once or twice a day and let it renew certs as needed.

To deploy the certs to the respective servers I suggest using an IT Automation tool like Ansible.  I have a dedicated VM that runs Ansible.  You can configure an ansible playbook to run from a daily cron job to copy updated certificates to remote servers and automatically reload services if the certificates have been updated.  Here’s an example of an Ansible Playbook which could be called daily to copy certs to all web-servers and reload nginx if the certs were updated or renewed:

Create a file web-servers-nginx.yml

- hosts: web-servers-nginx

  - name: Copy SSL certificates
      dest: /etc/dehydrated/certs/
      src: "/etc/dehydrated/certs/{{ item }}"
      mode: 0600
      follow: yes
    with_items: "{{ dehydrated_ssl_certs }}"
    register: sslcerts

  - name: Reload Nginx when certs change
    service: name=nginx state=reloaded
    when:  sslcerts.changed

Add the below to your Ansible inventory file (mine is namned ‘production’).  “” matches the primary name of the certificate, found in /etc/dehydrated/certs/

[web-servers-nginx] dehydrated_ssl_certs='[""]'

Execute the playbook with:

ansible-playbook -i production web-nginx-servers.yml

(note that the user that runs this needs to have permissions to read the certificates that dehydrated generated.  Easiest way to do that is to use the same user account to run dehydrated as you do for Ansible.  Also Ansible will need public/private key authentication setup to connect to the remote server without a password).

Then obviously you would have something like this in nginx:

ssl on;
ssl_certificate /etc/dehydrated/certs/;
ssl_certificate_key /etc/dehydrated/certs/;
ssl_stapling on;
ssl_stapling_verify on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;

(for the ssl_dhparam to work you’ll need to run the below command once on the web server):

cd /etc/ssl/certs
openssl dhparam -out dhparam.pem 4096

And after that nginx needs to be restarted.

If this is a public server I strongly suggest testing with SSLLabs to make sure chaining and security is setup correctly.