Skip to content
Dorian FINKEL
Let’s EncryptCertbotCloudflareTutorial · 2026 · 3 min read · Updated 9 October 2026
Level · IntermediateDuration · 15 min

A Let’s Encrypt wildcard certificate with certbot and Cloudflare

A single certificate for every subdomain, obtained through the DNS-01 challenge via the Cloudflare API, without opening a single port, and renewed automatically.

Prerequisites

  • A domain whose DNS is managed at Cloudflare
  • certbot and its Cloudflare plugin (python3-certbot-dns-cloudflare package on Debian / Ubuntu)

01Why DNS-01

To issue a certificate, Let’s Encrypt asks for proof of control over the domain. The DNS-01 challenge provides it through a temporary TXT record: no web server needs to be reachable, and it is the only method that allows a wildcard certificate (*.example.com).

02An API token with minimal rights

In Cloudflare, create a token with the Zone:DNS:Edit permission only, limited to the zones concerned. Store it in a file readable by root only: otherwise certbot warns about “Unsafe permissions”.

Example · ~/.secrets/certbot/cloudflare.ini
# Cloudflare API token used by certbot
dns_cloudflare_api_token = <your token>

03Request the certificate

A wildcard doesn’t cover the bare domain: request both names. The propagation delay gives the TXT record time to become visible before the check.

Example · Shell
chmod 600 ~/.secrets/certbot/cloudflare.ini

certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
  --dns-cloudflare-propagation-seconds 60 \
  -d example.com -d '*.example.com'

04Renewal

Let’s Encrypt certificates currently last 90 days. That is going down: 64 days from 10 February 2027, then 45 days in 2028. Automatic renewal is no longer optional.

The certbot package installs a systemd timer that renews certificates well before they expire. A deploy hook reloads the service using them, only when a certificate actually changed. Test the whole chain once:

Example · Shell
certbot renew --dry-run
systemctl list-timers | grep certbot

# Reload nginx after every successful renewal
printf '#!/bin/sh\nsystemctl reload nginx\n' | sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

Key takeaways

  • DNS-01: the only path to a wildcard, with no open port.
  • Token limited to Zone:DNS:Edit, file in chmod 600.
  • Request both the bare domain and the wildcard.
  • 90 days today, 64 in 2027, 45 in 2028: automate everything.
  • certbot renew --dry-run to validate renewal.

Example domain.

Official sources