The clearest explanation of DNS available. Covers the full resolution chain with diagrams. Essential before configuring any domain. cloudflare.com/learning →
You will configure DNS for every project you deploy. Get it wrong and your site is unreachable. Get it right and you can point domains to CDNs, route traffic between regions, verify domain ownership for SSL, and configure email authentication — all through DNS records.
When a browser requests api.yourapp.com, here's exactly what happens:
| Record | What it does | When you use it |
|---|---|---|
A | Maps a hostname → IPv4 address | Pointing api.yourapp.com to your EC2 IP |
AAAA | Maps a hostname → IPv6 address | Same as A, for IPv6 |
CNAME | Alias one hostname → another hostname | www.yourapp.com → yourapp.com; also CloudFront distributions |
MX | Mail exchange — where email for your domain is delivered | Google Workspace, Fastmail, etc. |
TXT | Arbitrary text data | Domain verification (Google, GitHub), SPF, DKIM (email auth) |
NS | Nameserver — which servers answer queries for your domain | Delegating a domain to Cloudflare |
CAA | Certificate Authority Authorization — which CAs can issue certs for your domain | Security hardening |
You cannot put a CNAME on a bare/apex domain (yourapp.com) — only on subdomains. Use Cloudflare's "CNAME flattening" or an ALIAS record (Route 53) for the apex. This trips everyone up the first time.
TTL (in seconds) tells DNS resolvers how long to cache your record before checking for updates.
Before any planned infrastructure change (new server, new IP), lower your TTL to 60 seconds 24 hours in advance. After the migration, bump it back to 3600. This minimises downtime during the cutover.
When you buy a domain (e.g., from Namecheap), the domain registrar sets the nameservers. Those nameservers hold your DNS records. When you move to Cloudflare, you change your domain's nameservers to Cloudflare's — Cloudflare then controls all DNS records.
# Check who controls DNS for a domain
dig NS yourapp.com
# Look up an A record
dig A api.yourapp.com
# Check what IP a domain resolves to
dig +short api.yourapp.com
# Query a specific nameserver directly
dig @ns1.cloudflare.com A yourapp.com
# Check TXT records (SPF, DKIM, verification)
dig TXT yourapp.com