Sub topic 5
Preparing DNS Records, Ports 80 and 443, and the Firewall
This chapter assumes you can use a Linux shell with sudo and have nginx installed. It also assumes you own a registered domain and know the basic DNS record types. Before you ask Let's Encrypt for a certificate, the outside world must be able to find your server by name and reach it on the right ports. Most failed first-time issuances come from a gap in this preparation, not from Certbot itself.
What the validator needs from you
When you request a certificate, the Let's Encrypt validation servers act as an ordinary client on the internet. For the HTTP-01 challenge they do three things:
- Look up your domain name in public DNS.
- Open a TCP connection to the resulting IP address on port 80.
- Request
http://yourname/.well-known/acme-challenge/<token>and compare the response to the expected value.
Any break in that path causes a validation failure. The path crosses four layers: public DNS, any cloud or network firewall in front of the host, the firewall on the host, and the web server process.
Check each layer in order, starting from DNS.
DNS records
Every name you put on the certificate needs a record that points at this server. For example.com and www.example.com, that usually means:
| Name | Type | Value | Purpose |
|---|---|---|---|
| `example.com` | A | `203.0.113.10` | IPv4 address of the server |
| `example.com` | AAAA | `2001:db8::10` | IPv6 address, only if the server really has one |
| `www.example.com` | CNAME | `example.com.` | Alias to the apex name |
Three points cause most of the trouble:
- A CNAME cannot share a name with other records. You cannot put a CNAME at the zone apex (
example.com) alongside the SOA and NS records. Use A and AAAA records there. - A stray AAAA record breaks validation. Let's Encrypt prefers IPv6 when a name has an AAAA record. If the record exists but nginx or the firewall does not serve IPv6, validation fails even though IPv4 works. Either make IPv6 work end to end or delete the AAAA record.
- Old records point elsewhere. If you migrated servers, a leftover A record can send the validator to the previous host.
Checking records with dig
Query the public DNS rather than your local resolver cache. The dig tool is in the dnsutils package on Debian and Ubuntu, and in bind-utils on RHEL-family systems.
dig +short A example.com
dig +short AAAA example.com
dig +short CNAME www.example.com
dig +short A example.com @1.1.1.1
curl -4 -s https://ifconfig.me; echoThe last command prints the public IPv4 address your server uses for outbound traffic. Run it on the server and compare it with the A record. They differ when the server sits behind NAT or a load balancer, and in that case you must forward the ports to the right machine.
TTL and propagation
Each record has a time to live (TTL), the number of seconds resolvers may cache it. If you just changed a record, resolvers that cached the old answer keep returning it until the TTL expires. Lower the TTL to 300 seconds a day before a migration, and wait for the old TTL to pass before you request the certificate. Let's Encrypt queries authoritative servers directly, but your own dig against a recursive resolver may still show stale data.
Optional CAA records
A CAA record tells certificate authorities which of them may issue for your domain. If no CAA record exists, any CA may issue. If one exists and does not name Let's Encrypt, issuance fails.
dig +short CAA example.comTo allow Let's Encrypt, publish this record in your DNS provider's interface:
example.com. 3600 IN CAA 0 issue "letsencrypt.org"CAA lookups walk up the tree. A CAA record on example.com also applies to www.example.com unless the subdomain has its own.
Ports 80 and 443
Two ports matter:
- Port 80 (HTTP) carries the HTTP-01 challenge. Let's Encrypt only validates on port 80 for this challenge type.
- Port 443 (HTTPS) serves your site after the certificate is installed. Visitors need it open.
Keep port 80 open permanently, even after you redirect all traffic to HTTPS. Renewal repeats the same validation, so closing port 80 later makes renewal fail about 60 days after issuance, when the first renewal attempt runs. The validator follows redirects, so a redirect from HTTP to HTTPS on the same name is fine.
You cannot restrict port 80 to a list of Let's Encrypt IP addresses. The validation servers run in several locations and their addresses are not published and can change. Allow port 80 from anywhere.
Is anything listening?
A firewall rule is useless if nothing is bound to the port. Check with ss:
sudo ss -tlnp | grep -E ':(80|443)\b'You should see nginx listening on 0.0.0.0:80 and [::]:80. If the output shows only 127.0.0.1:80, nginx is bound to loopback and the outside world cannot reach it. If another process such as Apache holds the port, nginx fails to start. Stop the other service or change its port.
The host firewall
Pick the tool your distribution uses. Do not enable a firewall over SSH before you allow SSH, or you will lock yourself out.
ufw (Ubuntu and Debian)
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verboseThe Nginx Full application profile opens 80 and 443 in one step, if the nginx package installed its profile.
firewalld (RHEL, Fedora, Rocky)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-servicesThe --permanent flag writes the rule to disk, and --reload applies it. Without --permanent, the rule disappears at the next reload or reboot.
Cloud security groups
Providers such as AWS, Google Cloud, and Azure filter traffic before it reaches your host. A correct host firewall does nothing if the security group blocks port 80. Add inbound rules for TCP 80 and 443 from 0.0.0.0/0 and, if you use IPv6, from ::/0. Rules for IPv4 do not cover IPv6.
Testing from outside
Tests run on the server itself prove little, because they skip the cloud firewall and often skip DNS. Test from another machine, such as your laptop or a different server:
curl -sI http://example.com/ | head -n 1
curl -4 -sI http://example.com/ | head -n 1
curl -6 -sI http://example.com/ | head -n 1
nc -zv example.com 80Any HTTP status line proves the path works, even a 404. A hang followed by a timeout usually means a firewall is silently dropping packets. An immediate "connection refused" usually means the packet arrived but nothing is listening.
To rehearse the real challenge, create a test file and fetch it from outside:
sudo mkdir -p /var/www/html/.well-known/acme-challenge
echo ok | sudo tee /var/www/html/.well-known/acme-challenge/test >/dev/null
curl http://example.com/.well-known/acme-challenge/testRun the curl from a different machine. It should print ok. Remove the test file afterward.
Situations that need extra care
- CDN or reverse proxy in front. If a service such as Cloudflare proxies your name, the validator reaches the proxy, not your server. Either configure the proxy to pass
/.well-known/acme-challenge/through, use DNS-01 validation, or pause the proxy during issuance. - Servers without a public address. HTTP-01 cannot work for a host that is not reachable from the internet. DNS-01 does not require inbound access and is the alternative covered later in this tutorial.
- Several virtual hosts. The
server_namein nginx must match the requested name, or the request may land in a differentserverblock that returns the wrong content. - Wildcard names. HTTP-01 cannot validate
*.example.com. Wildcards need DNS-01.
Exercise
Your A record for example.com is correct and ufw allows ports 80 and 443. Certbot still reports a timeout when Let's Encrypt connects. A curl from your laptop to port 80 also hangs. Name two layers you would check next, and one command for each.
Show answer
First, the cloud security group or network firewall in front of the host, which may not allow inbound TCP 80. Check the provider's inbound rules for port 80 from 0.0.0.0/0 and ::/0. Second, whether nginx is listening on a public address. Run "sudo ss -tlnp | grep ':80'" and confirm it is bound to 0.0.0.0 or [::], not only 127.0.0.1. A third possible cause is a stale AAAA record pointing at an IPv6 address that is not served. Check it with "dig +short AAAA example.com".