What is a CNAME record? Explanation and examples
Published on June 19, 2026 7 min read
Learn what a CNAME record is and how to use one to point a subdomain as an alias to another hostname, with clear examples and key rules.
A CNAME record is a DNS setting that points one hostname to another hostname. Instead of an IP address, you give a CNAME record a target name, for example www.example.com pointing to example.com. This page explains what a CNAME record is, how it works, when to use one, and which rules and limits to keep in mind.
What is a CNAME record?
CNAME stands for Canonical Name. It is one of the standard DNS record types (type 5) and is defined in RFC 1035 from 1987. A CNAME record turns a name into an alias: it maps that name to another hostname, known as the canonical name.
The difference from an A record or AAAA record matters. An A record links a name to an IP address. A CNAME record links a name to another name. The DNS server then looks up the matching IP address at that other name itself.
How does a CNAME record work?
Say a visitor requests www.example.com and a CNAME record there points to example.com. Here is what happens:
- The DNS server sees the CNAME record and knows that www.example.com is an alias of example.com.
- The server then looks up the A and AAAA records of example.com.
- Those records return the IPv4 and IPv6 address of the server.
- The visitor connects to that address.
The benefit is that you only manage the underlying address in one place. If the IP address of example.com changes, www.example.com follows automatically, because the alias points to the name and not to a fixed address.
When do you use a CNAME record?
A CNAME record is useful whenever you want one name to follow another name. The most common cases are:
- www to your main domain: the classic example is www.example.com as an alias of example.com, so both addresses reach the same website.
- External services and CDNs: many platforms for online stores, newsletters, or a content delivery network (CDN, a network that serves your site faster) ask you to point a subdomain to their servers with a CNAME.
- Domain verification: some services have you create a unique CNAME record to prove that you own the domain.
- Easy maintenance: because the alias follows the name and not the address, you only need to update the target when you move to a new server.
How to create a CNAME record
The exact steps depend on where you manage your DNS, but the approach is similar everywhere. In your DNS manager or control panel, you create a new record with the following details:
- Type: choose CNAME.
- Name (host): the name you want to set as an alias, such as www or a subdomain like shop.
- Target (value): the full hostname you are pointing to, such as example.com or a name your external service gives you.
- TTL: how long the record may be cached. 3600 seconds (one hour) is a common value.
- Save: save the record and wait for the change to take effect.
At LJPc hosting, a new DNS zone already includes a default www record as a CNAME that points to your main domain, so www and your bare domain use the same address right away.
A new or changed CNAME does not appear everywhere at once. Because of caching, it can take up to 48 hours for the change to roll out worldwide, although it is usually much faster.
Example of a CNAME record
Below are two common examples. In the first case, www.example.com is an alias of example.com. In the second case, shop.example.com points to the server of an external service.
| Name | Type | Target |
|---|---|---|
| www | CNAME | example.com |
| shop | CNAME | customers.external-service.com |
Important rules and limits
A CNAME record is powerful, but a few strict rules apply. Break them and your domain or email may stop working.
No CNAME on your main domain
You cannot set a CNAME record on the main domain itself, that is example.com with nothing in front of it. This is called the apex or root. The DNS standard requires that a CNAME record not coexist with any other record on the same name, and the apex always has mandatory NS and SOA records, so a CNAME there is never valid. If you still want your bare domain to point elsewhere, use an A or AAAA record, or an alternative your provider offers such as an ALIAS record, an ANAME record, or CNAME flattening.
A CNAME always stands alone
On the name that holds a CNAME record, no other records are allowed. So you cannot put both a CNAME and a separate A record or TXT record on www at the same time. If you need another record type on that name in addition to the alias, you have to choose a different setup.
MX and NS never point to an alias
According to the DNS standard (RFC 2181), the target of an MX record or NS record may not be an alias. So in an MX record, point your mail server directly to a hostname that has an A or AAAA record, not to a CNAME.
Avoid long chains
A CNAME may point to a name that is itself a CNAME, but every extra step costs a lookup and makes resolution slower and more error-prone. Keep chains as short as possible and point straight to the final hostname where you can.
How to check a CNAME record
You can verify a CNAME record yourself. Use one of these commands from your own computer.
| Operating system | Command |
|---|---|
| macOS or Linux | dig CNAME www.example.com +short |
| Windows | nslookup -type=CNAME www.example.com |
The answer shows the canonical name the alias points to. If you see no CNAME, the record has not propagated yet or sits on a different name.
Troubleshooting
If a CNAME record does not work as expected, check these common causes.
| Problem | Cause | Solution |
|---|---|---|
| The change is not visible yet | The old value is still cached (TTL) | Wait until the TTL expires, up to 48 hours |
| Error when saving on the main domain | A CNAME is not allowed on the apex | Use an A or AAAA record, or an ALIAS or ANAME record |
| The record will not save next to other records | A CNAME may not sit alongside other records on the same name | Remove the other records or pick a different name |
| Email does not arrive | An MX record points to a CNAME | Point the MX record to a name with an A or AAAA record |
With a CNAME record, you keep your DNS tidy: you manage the underlying address in one place and let aliases move along automatically. Still stuck? Contact support and we will be glad to help.
Frequently asked questions
What is the difference between a CNAME record and an A record?
An A record links a name to an IP address. A CNAME record links a name to another hostname. With a CNAME, the DNS server then looks up the IP address at that other name itself.
Can I put a CNAME record on my main domain?
No. The DNS standard requires that a CNAME record not coexist with any other record on the same name, and the apex always has mandatory NS and SOA records, so a CNAME there is never valid. On the main domain, use an A or AAAA record, or an ALIAS or ANAME record if your provider supports it.
How long does it take for a CNAME record to work?
Usually within a few minutes to a few hours. Because of caching, in the worst case it can take up to 48 hours for the change to apply everywhere. The TTL controls how long old data is kept.
Can a CNAME record point to another CNAME record?
It can, but it is not recommended. Every extra link costs a lookup and makes name resolution slower and more error-prone. Point straight to the final hostname where you can.
How do I check a CNAME record?
On macOS or Linux, use the command dig CNAME name +short. On Windows, use nslookup -type=CNAME name. The answer shows the hostname the alias points to.
Can I point an MX record to a CNAME?
No, the DNS standard does not allow it. An MX record must point to a hostname that has its own A or AAAA record, not to an alias.