Chapter 3 · Lesson 6 of 22
Domains and HTTPS

Wildcard certificates explained (*.example.com)

A wildcard certificate such as "*.example.com" secures every single-level subdomain of a domain with one certificate.

By the end you will

Decide when a wildcard certificate fits and know what it covers and how it is issued.

Time
14 min
Level
Beginner
Check
4 questions

A wildcard certificate such as *.example.com covers any single subdomain (app.example.com, api.example.com) but not example.com itself and not two-level names like a.b.example.com. Let’s Encrypt issues wildcards only after a DNS-01 check, where you publish a TXT record.

A short history#

Wildcard names are part of the certificate standards, but Let’s Encrypt did not issue them until March 2018, when its newer ACME protocol version launched. Before that, free wildcards were not available from it, so many people ran one certificate per name.

How it works#

A certificate lists the names it is valid for in its Subject Alternative Name (SAN) field. A browser compares the name in the address bar with that list. A wildcard entry *.example.com matches exactly one label in the leftmost position. So app.example.com matches, but example.com (no label) does not, and a.b.example.com (two labels) does not. Wildcards cannot be nested, so *.*.example.com is not valid.

Let’s Encrypt must see that you control the domain. For a normal name it can fetch a token over HTTP on port 80 (HTTP-01). For a wildcard that is not enough, because proving you control one web server does not prove you control every possible subdomain. So Let’s Encrypt issues wildcards only through the DNS-01 challenge: your client creates a TXT record named _acme-challenge.example.com with a value the CA gave it, and the CA looks it up in DNS. That proves control of the whole zone.

Doing that by hand every 90 days is impractical, so clients use your DNS provider’s API to create and remove the TXT record. The same API key can edit your whole zone, which is why the next section matters.

What it covers#

*.example.com matches one label in front of the domain:

  • app.example.com is covered.
  • api.example.com is covered.
  • example.com is not covered. List it as its own name.
  • a.b.example.com is not covered (two levels).

Trade-offs#

  • Good: one certificate for many subdomains, and new subdomains work with no new request. It also keeps private subdomain names out of public certificate logs.
  • Cost: your server needs a DNS API key, which is powerful. Store it carefully and scope it to the one zone.
  • Cost: one private key now protects every subdomain. If it leaks, all of them are exposed.
  • Alternative: separate certificates per name need no DNS access and limit the damage of one leak.

Comparing the options#

OptionNames coveredNeeds DNS APIBlast radius of a leaked key
One certificate per nameOneNoOne name
Multi-name certificateA fixed listNoThe listed names
WildcardAny single-label subdomainYes, for DNS-01Every subdomain

Common misconceptions#

  • A wildcard does not cover the bare domain, so list both names.
  • A wildcard does not cover deeper names such as a.b.example.com.
  • A wildcard is not an access control. Unknown names still get a valid certificate if your server answers for them.

When not to use a wildcard#

Skip it if you have one or two names, if your DNS host has no API and you cannot delegate the challenge, or if one compromised server should not be able to impersonate every subdomain.

Check it worked#

See it for yourself on any server that has a wildcard certificate:

bash
echo | openssl s_client -connect app.example.com:443 -servername app.example.com 2>/dev/null | openssl x509 -noout -ext subjectAltName

s_client connects and prints the certificate, -servername sends the name for SNI, and x509 -ext subjectAltName prints the name list. What you should see: a DNS:*.example.com entry and usually DNS:example.com. Compare it with the name you visited. The -ext option needs OpenSSL 1.1.1 or newer. For the full walkthrough see Inspect a TLS certificate with OpenSSL.

To request one yourself with certbot, with the names listed explicitly:

bash
sudo certbot certonly --manual --preferred-challenges dns -d example.com -d '*.example.com'

Certbot prints the TXT record to create. Check it before you continue with dig +short TXT _acme-challenge.example.com. Manual mode does not renew automatically. For renewal, use a certbot DNS plugin for your provider. Add --staging first to practice.

Edge cases and gotchas#

  • The bare domain is not included. *.example.com does not cover example.com. Request both names.
  • Two levels need their own wildcard. a.b.example.com needs *.b.example.com or its own name.
  • Both names share one TXT name. Requesting example.com and *.example.com together can require two TXT values at _acme-challenge.example.com. Some DNS panels handle several values on one name, and some overwrite the first. Check with dig that both exist.
  • DNS propagation. A slow provider may not show the TXT record before the CA checks. Increase your client’s propagation wait setting.
  • A specific certificate can be preferred. A server with both a wildcard and a certificate for one exact name picks per its config, and an exact-name certificate is not always chosen the way you expect. Check which one is served with openssl s_client.
  • A wildcard hides nothing about the zone itself. Anyone can still try names, and unknown names under it still get a valid certificate if your server answers for them. Do not treat a wildcard as access control.
  • A CNAME for _acme-challenge delegation. You can delegate the challenge record to another zone with a CNAME if your DNS host lacks an API. Do it only if you understand who then controls that zone.

Troubleshooting#

SymptomLikely causeFix
DNS challenge fails, the CA says the TXT record was not foundRecord not visible yet, or wrong nameCheck dig +short TXT _acme-challenge.example.com, wait longer
API permission or authentication errorThe DNS token cannot edit the zoneGive the token rights to that zone only
Browser warns on a.b.example.comTwo levels are not coveredAdd *.b.example.com or the exact name
NET::ERR_CERT_COMMON_NAME_INVALID on the bare domainBare domain not listed on the certificateReissue with -d example.com -d '*.example.com'
Wildcard request refused over HTTPHTTP-01 cannot issue wildcardsUse --preferred-challenges dns with a DNS plugin
Renewal fails months laterManual mode, or the token was rotatedUse a DNS plugin and update the saved credentials
Rate limit messageToo many recent requestsWait, and test with --staging
Certificate is issued but the bare domain shows an errorThe bare domain was not listedRequest example.com and *.example.com together
Old and new certificate names mix upTwo lineages exist in /etc/letsencryptRun sudo certbot certificates and delete the one you do not use

Real-world scenario#

Kai hosts a dozen internal tools at names like grafana.example.com, git.example.com and a few more he adds every month. Separate certificates mean separate renewals and a public record of each name. He decides on a wildcard, using his DNS host’s certbot plugin so renewal is automatic.

bash
sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /root/cf.ini -d example.com -d '*.example.com'
sudo certbot certificates

The plugin name depends on the DNS provider, and the token file is readable by root only (chmod 600). The listing shows both names on one certificate. A month later he adds wiki.example.com and needs no new request. Then a coworker asks why old.dev.example.com fails: it has two labels, so he adds *.dev.example.com as a second name. The challenge itself is described in HTTPS and Let’s Encrypt, and the renewal routine in renew Let’s Encrypt certificates.

Quick reference#

NameCovered by *.example.com
app.example.comyes
example.comno, list it separately
a.b.example.comno, needs *.b.example.com
*.*.example.comnot valid

Challenge: DNS-01 only, TXT record at _acme-challenge.example.com. Practice with --staging.

Security and safety notes#

  • Treat the DNS API token like a password: scope it to one zone, store it with restricted file permissions, and never commit it.
  • Protect the wildcard private key. Anyone who has it can impersonate every subdomain.

Next#

Read a certificate yourself with Inspect a TLS certificate with OpenSSL.

Check what you learned4 questions
1Which name is covered by a certificate for *.example.com only?
2Why can a wildcard not be issued with the HTTP-01 challenge?
3What is a real cost of using one wildcard certificate for every subdomain?
4Which names should you request to cover example.com and every one-level subdomain?

Frequently asked questions

Does *.example.com cover example.com?

No. The bare domain must be listed as its own name, so request both example.com and *.example.com.

Can I use a wildcard for a.b.example.com?

Not with *.example.com. That covers one label only. You would need *.b.example.com as its own name on the certificate.

Can I get a wildcard with the HTTP-01 challenge?

No. Let's Encrypt issues wildcards only through the DNS-01 challenge.

Is a wildcard certificate the same as one certificate with many names?

No. A multi-name certificate lists each hostname and is visible in public logs. A wildcard matches any single label, so new subdomains work without a new request.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios