Certbot DNS-01 Challenge TXT Record Mismatch on Alpine Linux
Troubleshoot Certbot DNS-01 TXT record mismatch on Alpine Linux. Learn why your ACME challenge fails and how to resolve common DNS propagation issues.
Troubleshoot Certbot DNS-01 TXT record mismatch on Alpine Linux. Learn why your ACME challenge fails and how to resolve common DNS propagation issues.
Certbot DNS-01 Challenge TXT Record Mismatch on Alpine Linux
When securing your web server with Let's Encrypt using Certbot, the DNS-01 challenge is often preferred for wildcard certificates or when port 80/443 is not directly accessible (e.g., behind a load balancer). This method requires you to prove ownership of your domain by adding a specific TXT record to your domain's DNS zone. A common issue, especially in production environments, is a mismatch between the TXT record Certbot expects and what it actually finds when verifying the challenge. This guide will walk you through diagnosing and resolving this "TXT records mismatch" error specifically on Alpine Linux systems.
Symptom & Error Signature
The most direct symptom is Certbot failing to obtain or renew a certificate, displaying an error message similar to the following in your terminal output:
Challenge failed for domain yourdomain.com
Challenge failed for domain www.yourdomain.com
tls-sni-01 and http-01 challenges did not work.
The following errors were reported by the server:
Domain: yourdomain.com
Type: unauthorized
Detail: The key authorization value specified in the DNS-01 challenge was expected to be "YOUR_EXPECTED_TXT_VALUE" but was "YOUR_OBSERVED_TXT_VALUE".
This often means that a TXT record for this domain was not correctly set. Please check the DNS record and ensure it is correct.
Hint: The Certificate Authority failed to verify the DNS TXT record for _acme-challenge.yourdomain.com.
Ensure that this record is in place and that it is published to the internet correctly.
If using a DNS plugin, you might also see:
Failed to install a certificate in the webserver, and an issue occurred during the verification of the certificate request.
Please check your logs for more information.
And in /var/log/letsencrypt/letsencrypt.log:
202X-XX-XX XX:XX:XX,XXX:DEBUG:acme.challenges:{"type": "dns-01", "token": "YOUR_TOKEN"}
202X-XX-XX XX:XX:XX,XXX:DEBUG:certbot.reporter:Reporting to user: The key authorization value specified in the DNS-01 challenge was expected to be "YOUR_EXPECTED_TXT_VALUE" but was "YOUR_OBSERVED_TXT_VALUE".
Root Cause Analysis
The "TXT records mismatch" error indicates that the ACME server (Let's Encrypt) could not find the exact TXT record it expected when it queried your domain's DNS. Several factors can contribute to this:
- DNS Propagation Delays: This is the most common culprit. After you update a DNS record, it takes time for the changes to propagate across the internet's various DNS servers. If Certbot checks too soon, it might see an old or non-existent record.
- Incorrect TXT Record Value:
- Typo: A simple error in copying the long string Certbot provides.
- Leading/Trailing Whitespace: Invisible characters can cause a mismatch.
- Incorrect Format: Some DNS providers require quoting, others don't.
- Incorrect TXT Record Name: The record must be named
_acme-challenge.yourdomain.com(or_acme-challengeif your DNS provider automatically appends the base domain). Errors in the prefix or subdomain can lead to the record not being found. - Multiple TXT Records: If previous
_acme-challengerecords were not removed, or if multiple challenges are run concurrently, the ACME server might pick up an outdated or incorrect record from a set of valid ones. - DNS Provider Caching: Your local machine's DNS resolver or your DNS provider's internal caching might serve stale data even after the record is updated.
- Certbot DNS Plugin Misconfiguration (if applicable): If you're using an automated Certbot DNS plugin (e.g.,
certbot-dns-cloudflare,certbot-dns-route53), an issue with API credentials, permissions, or rate limiting from the DNS provider can cause it to fail to set or verify the record correctly. - Firewall Restrictions: While less common for DNS, some restrictive firewalls might interfere with DNS queries, though this usually manifests as a timeout rather than a mismatch.
- Alpine Linux Specifics: Alpine's minimalist nature means tools like
digare not installed by default, making manual verification slightly different initially.
Step-by-Step Resolution
Follow these steps to diagnose and resolve the Certbot DNS-01 TXT record mismatch error.
1. Understand the Expected TXT Record Value
First, carefully examine the Certbot error message. It explicitly states what TXT record value it expected to find. Make a note of this value and the full subdomain it was looking for (e.g., _acme-challenge.yourdomain.com).
Detail: The key authorization value specified in the DNS-01 challenge was expected to be "YOUR_EXPECTED_TXT_VALUE"
This YOUR_EXPECTED_TXT_VALUE is crucial.
2. Manually Verify the TXT Record at Public DNS Resolvers
It's essential to check what public DNS resolvers are seeing, not just your local cached results.
Install
bind-toolson Alpine Linux: If you don't havedig(which is highly recommended for DNS troubleshooting), install it:sudo apk add bind-toolsQuery your DNS record: Use
digto query authoritative and public DNS servers for the_acme-challengeTXT record for your domain. Replaceyourdomain.comwith your actual domain.# Query your domain's authoritative DNS servers dig TXT _acme-challenge.yourdomain.com +short # Query Google's public DNS (8.8.8.8) dig TXT _acme-challenge.yourdomain.com @8.8.8.8 +short # Query Cloudflare's public DNS (1.1.1.1) dig TXT _acme-challenge.yourdomain.com @1.1.1.1 +shortExample Output:
"YOUR_OBSERVED_TXT_VALUE"Compare the
YOUR_OBSERVED_TXT_VALUEwithYOUR_EXPECTED_TXT_VALUEfrom Certbot's error message. If they differ, or if no value is returned, you've found the problem.If
digreturns multiple TXT records for_acme-challenge.yourdomain.com, this could also be the cause of the mismatch. Let's Encrypt expects a single, unambiguous record.
3. Correct the TXT Record at Your DNS Provider
Log in to your domain's DNS provider (e.g., Cloudflare, AWS Route 53, GoDaddy, Namecheap, etc.) and navigate to your DNS management zone.
- Locate the
_acme-challengeTXT record: Find the TXT record that Certbot is attempting to verify. - Ensure correct Name/Host:
- The "Host" or "Name" field for the TXT record should be
_acme-challenge. Some providers may require_acme-challenge.yourdomain.comexplicitly, while others automatically append the base domain. If in doubt, try_acme-challengefirst.
- The "Host" or "Name" field for the TXT record should be
- Ensure correct Value/Data:
- The "Value" or "Data" field must exactly match the
YOUR_EXPECTED_TXT_VALUEprovided in Certbot's error message. No extra spaces, no missing characters, no quotes (unless your provider specifically requires them within the value field itself, which is rare).
- The "Value" or "Data" field must exactly match the
- Remove Duplicate or Stale Records:
Ensure there is only one TXT record for
_acme-challenge.yourdomain.com. If you find multiple, delete all but the most current one (or delete all and re-add the correct one). Stale records from previous failed attempts are a common source of this error. - Set a Low TTL (Time To Live):
- Temporarily set the TTL for the
_acme-challengeTXT record to a very low value, such as 60 or 120 seconds. This will speed up propagation of your changes. Remember to set it back to a higher value (e.g., 3600 seconds) after you've successfully obtained the certificate.
- Temporarily set the TTL for the
4. Wait for DNS Propagation
After making changes at your DNS provider, you must wait. Even with a low TTL, it can take a few minutes up to an hour or more for changes to propagate globally, especially if the old record was cached heavily.
- Continue using
digcommands from Step 2, particularly querying@8.8.8.8and@1.1.1.1, until you consistently see theYOUR_EXPECTED_TXT_VALUEin the output. - You can also use online DNS checking tools like
dnschecker.orgorwhatsmydns.netto verify global propagation.
5. Re-run Certbot
Once you've confirmed that the correct TXT record is visible globally via public DNS resolvers, you can re-run Certbot.
If using a manual challenge: Certbot will prompt you again to add the TXT record, but this time you've ensured it's correct.
sudo certbot certonly --manual --preferred-challenges dns -d yourdomain.com -d *.yourdomain.comIf using a DNS plugin (recommended for automation): Certbot will attempt to set and verify the record automatically.
# Example for Cloudflare plugin sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d yourdomain.com -d *.yourdomain.com --email [email protected] --agree-tos --non-interactive # Test renewal (highly recommended) sudo certbot renew --dry-runEnsure your DNS plugin credentials file (
/etc/letsencrypt/cloudflare.iniin the example) has the correct permissions (chmod 600) to prevent unauthorized access to your DNS API keys.
6. Alpine Linux Specific Considerations
- Certbot Installation: On Alpine, Certbot is typically installed via
apk:sudo apk add py3-certbot # For Nginx integration: sudo apk add py3-certbot-nginx # For DNS plugins (example for Cloudflare): sudo apk add py3-certbot-dns-cloudflare - Persistent Configuration: If you're running Certbot within a Docker container on Alpine, ensure that
/etc/letsencryptand any plugin credential files are mounted as persistent volumes so certificates and configurations are not lost on container restarts.
7. Review Certbot Logs for Further Clues
If the issue persists, review the Certbot logs located at /var/log/letsencrypt/ for more detailed information. The letsencrypt.log file can often provide specific errors reported by the ACME server or issues encountered by the DNS plugin.
sudo cat /var/log/letsencrypt/letsencrypt.log | tail -n 100
By following these steps, systematically verifying your DNS configuration, and allowing ample time for propagation, you should be able to resolve the Certbot DNS-01 challenge TXT record mismatch error on your Alpine Linux system.
Our Production Verification Guarantee
Encountering a bug not covered here or running a non-standard kernel configuration? Our solutions are continually refined against real production incidents. Submit an environment trace for our editorial team to replicate.