CNAME record
Learn what a DNS CNAME record is, how it creates domain aliases, key limitations (especially for root domains), lookup methods, best practices, and troubleshooting.
What Is a CNAME Record in DNS?
TL;DR
A CNAME record (Canonical Name) creates an alias, it points one domain name to another domain name (not directly to an IP).
DNS resolvers follow the CNAME to the target domain and resolve its A or AAAA record.
This is ideal for subdomains (e.g. www → root domain, or CDN endpoints), but cannot be used at the root domain if other records (MX, TXT, etc.) exist.
How CNAME Records Work
When a resolver sees a CNAME:
- It stops looking for other records at that name.
- It queries the target domain instead.
- It continues until it finds an A/AAAA record (or another CNAME, but avoid long chains).
CNAMEs are great when the target IP might change (e.g. CDN, hosted service), update the target's A record once, and all aliases follow.
Common Use Cases
- www alias:
www.example.com→example.com - CDN integration:
cdn.example.com→ CloudFront / Akamai endpoint - Third-party services:
blog.example.com→ WordPress.com, GitHub Pages, etc. - Subdomain redirects: Alias subdomains to different providers without duplicating IPs
- Easier migrations: Change one target instead of many A records
How to Lookup CNAME Records
dig www.example.com CNAMEnslookup -type=CNAME www.example.comRecord Format
NAME TTL CLASS TYPE VALUE
www.example.com. 3600 IN CNAME example.com.- VALUE: Must be another domain name (FQDN with trailing dot recommended)
- Only one CNAME per name allowed
- No other records (A, MX, TXT, etc.) can exist at the same name
Valid Examples
Classic www alias
www.example.com. CNAME example.com.
example.com. A 192.0.2.1CDN example
cdn.example.com. CNAME d1234567890.cloudfront.net.GitHub Pages / hosted service
blog.example.com. CNAME username.github.io.Multiple subdomains
api.example.com. CNAME api.backend-service.net.
shop.example.com. CNAME shops.myshopify.com.CNAME vs A / AAAA Records
| Feature | CNAME | A / AAAA |
|---|---|---|
| Points to | Domain name | IP address |
| Extra DNS lookup | Yes (adds latency) | No |
| Allowed at root | No (if other records exist) | Yes |
| Multiple per name | No (only one CNAME) | Yes |
| Other records allowed | No | Yes |
| Best for | Changing targets (CDN, hosting) | Static/performance-critical |
→ See also: A Record, AAAA Record
Frequently Asked Questions
Can I use CNAME at the root domain (example.com)?
Can a CNAME point to another CNAME?
What's better: CNAME or A record?
Use CNAME for flexibility when the target might change (CDN, SaaS).
Can I have CNAME and other records at the same name?
References
Related: A Record · AAAA Record · DNS Basics