What is a CNAME Record?
A CNAME (Canonical Name) record creates an alias from one hostname to another. Instead of mapping directly to an IP address like an A record, a CNAME points to another hostname that eventually resolves to an IP. The name you're aliasing is called the "alias", and the hostname it points to is the "canonical name."
CNAME Record example
www.example.com. 3600 IN CNAME example.com. blog.example.com. 3600 IN CNAME mysite.wordpress.com. shop.example.com. 3600 IN CNAME myshop.myshopify.com.
When to Use a CNAME Record
CNAME records are ideal when:
- ▸You're hosting with a platform like Vercel, Netlify, or GitHub Pages that gives you a hostname (not an IP)
- ▸You want multiple subdomains to point to the same place without maintaining multiple A records
- ▸The destination IP address changes frequently and the provider manages it
- ▸You want
www.yourdomain.comto resolve the same asyourdomain.com
Real-World Examples
Hosting on Vercel
CNAME for Vercel deployment
# Point your subdomain to your Vercel deployment www.myapp.com. CNAME cname.vercel-dns.com.
Hosting on GitHub Pages
CNAME for GitHub Pages
# Point a custom domain to GitHub Pages www.myblog.com. CNAME yourusername.github.io.
Critical Rules for CNAME Records
⚠ Warning: CNAME records cannot be used on the root (apex) domain. You cannot set
example.com itself as a CNAME — only subdomains like www.example.com. This is a fundamental DNS specification requirement.- ▸No root domain CNAME:
example.com CNAME something.else.comis invalid - ▸No mixing: A hostname with a CNAME cannot have any other records. No MX, no A, no TXT on the same name.
- ▸No pointing to IPs: CNAME values must be hostnames, never IP addresses
- ▸No CNAME chains (avoid): CNAME pointing to another CNAME is technically allowed but adds latency and is bad practice
Note: The root domain CNAME problem is why Cloudflare invented "CNAME flattening" (also called ALIAS or ANAME records). Cloudflare resolves the CNAME to an IP at their edge and serves it as an A record, making root domain aliases possible.
CNAME Lookup Process
When a browser looks up www.example.com and it's a CNAME:
- ▸DNS resolver finds
www.example.com CNAME example.com - ▸Resolver then looks up
example.comto find its A record - ▸Returns the final IP address to the browser
- ▸Extra lookup happens — CNAME adds one round trip vs. a direct A record
Common Mistakes
- ▸Setting a CNAME on the root domain — this breaks your entire domain
- ▸Creating MX records on a hostname that has a CNAME — email will stop working
- ▸Forgetting the trailing dot in zone files (providers usually handle this for you)
- ▸Creating CNAME chains that add unnecessary DNS lookups
- ▸Pointing CNAME to an IP address — use an A record instead