CNAME Records Explained
Understand how CNAME records work, their limitations, and when to use them. Includes examples for the DNScale dashboard and API.
A CNAME (Canonical Name) record creates an alias from one domain name to another. Instead of pointing to an IP address, a CNAME points to another domain name, which is then resolved to get the final IP address.
How CNAME Records Work
When a DNS resolver encounters a CNAME record, it follows the alias to find the actual IP address:
blog.example.com. 3600 CNAME example.com.
example.com. 3600 A 192.0.2.1Query flow:
- Client asks for
blog.example.com - DNS returns CNAME pointing to
example.com - DNS then resolves
example.comto192.0.2.1 - Client connects to
192.0.2.1
Common Use Cases
Subdomain Aliases
Point multiple subdomains to the same destination:
www.example.com. 3600 CNAME example.com.
blog.example.com. 3600 CNAME example.com.
shop.example.com. 3600 CNAME example.com.CDN Integration
Point your domain to a CDN provider:
www.example.com. 3600 CNAME d1234.cloudfront.net.
static.example.com. 3600 CNAME example.b-cdn.net.Cloud Service Integration
Point subdomains to cloud platforms:
app.example.com. 3600 CNAME myapp.herokuapp.com.
docs.example.com. 3600 CNAME example.gitbook.io.Email Service Verification
Many email services require CNAME records:
em1234.example.com. 3600 CNAME u1234.wl.sendgrid.net.Record Format
| Field | Description | Example |
|---|---|---|
| Name | Subdomain to alias | www, blog, api |
| Type | Record type | CNAME |
| Content | Target domain name | example.com. |
| TTL | Time to live (seconds) | 3600 |
Important Limitations
1. Cannot Use at Apex/Root Domain
CNAME records cannot be used at the root domain (apex):
# ❌ NOT ALLOWED
example.com. CNAME other.com.
# ✅ ALLOWED
www.example.com. CNAME other.com.For apex domains, use ALIAS records instead.
2. Must Be the Only Record at That Name
A CNAME cannot coexist with other record types at the same name:
# ❌ NOT ALLOWED - conflicts with CNAME
www.example.com. CNAME example.com.
www.example.com. TXT "verification=abc123"
# ✅ ALLOWED - CNAME is the only record
www.example.com. CNAME example.com.3. Adds Lookup Latency
Each CNAME introduces an additional DNS lookup, which can increase latency. For performance-critical applications, consider using A/AAAA records directly.
Adding a CNAME Record
Using the Dashboard
- Navigate to your zone in the DNScale dashboard
- Click Add Record
- Configure the record:
- Name: Enter the subdomain (e.g.,
www,blog) - Type: Select
CNAME - Value: Enter the target domain name
- TTL: Set the cache duration (default: 3600)
- Name: Enter the subdomain (e.g.,
- Click Create Record
Using the API
Create a CNAME record:
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "www",
"type": "CNAME",
"content": "example.com",
"ttl": 3600
}'Point subdomain to CDN:
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "cdn",
"type": "CNAME",
"content": "d1234567.cloudfront.net",
"ttl": 3600
}'API Response:
{
"status": "success",
"data": {
"message": "Record created successfully",
"record": {
"id": "encoded-record-id",
"name": "www.example.com.",
"type": "CNAME",
"content": "example.com.",
"ttl": 3600,
"disabled": false
}
}
}Best Practices
-
Use trailing dots - The target domain should technically end with a dot (e.g.,
example.com.), though DNScale handles this automatically -
Check for conflicts - Ensure no other records exist at the CNAME name
-
Consider TTL carefully - Use shorter TTLs if the target might change (e.g., during CDN migrations)
-
Don't chain too many CNAMEs - While DNS allows CNAME chains, they add latency and complexity
-
Use ALIAS for apex - If you need CNAME-like behavior at the root domain, use ALIAS records
CNAME vs ALIAS vs A Record
| Feature | CNAME | ALIAS | A |
|---|---|---|---|
| Points to | Domain name | Domain name | IP address |
| Works at apex | ❌ No | ✅ Yes | ✅ Yes |
| Can coexist with other records | ❌ No | ✅ Yes | ✅ Yes |
| Extra DNS lookup | Yes | No (resolved at authoritative) | No |
Testing CNAME Records
Verify your CNAME record with dig:
dig CNAME www.example.com
# Follow the chain to get the final IP
dig +trace www.example.comRelated Record Types
Conclusion
CNAME records are invaluable for simplifying DNS management, especially when integrating with third-party services. Understanding their limitations—particularly around apex domains and record coexistence—helps you make the right choice between CNAME, ALIAS, and direct A/AAAA records.