What is CNAME?
CNAME (Canonical Name) is a DNS record that makes one domain name an alias for another domain name.
In simpler terms: CNAME says: "this name is just another name for another domain".
Why CNAME is needed
CNAME is used to:
- point several names at the same resource
- avoid duplicating IP addresses in DNS
- simplify managing domains and subdomains
For example:
www.example.com -> example.com
www.example.com is not a separate site,
just another name for example.com.
How CNAME works
- The client requests:
www.example.com
- DNS sees the CNAME:
www.example.com -> example.com
- DNS then looks up records for example.com
- It finds an A / AAAA record and returns the IP
A CNAME does not contain an IP address itself.
Example of a CNAME record
Simplified:
| Name | Type | Value |
|---|---|---|
| www.example.com | CNAME | example.com |
| example.com | A | 93.184.216.34 |
In total:
www.example.com -> example.com -> 93.184.216.34
Important CNAME restrictions
This is often asked in interviews:
A CNAME cannot be used for the domain root (example.com)
(in classic DNS)
A name with a CNAME must not have other DNS records (A and CNAME cannot coexist)
So:
www.example.com-> CNAME is fineexample.com-> usually A / AAAA
When CNAME is especially useful
- CDNs (Cloudflare, CloudFront, etc.)
- external services (GitHub Pages, Heroku)
- when the IP can change often
- when one service needs to be reachable under different names
Real-life example
CNAME is like:
- a person's alias
- there is one real name, but you can address them differently
Short interview answer
Remember this formulation:
CNAME is a DNS record that indicates one domain name is an alias for another domain name, and it redirects DNS resolution to it.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.