# CNAME record

A CNAME (canonical name) record makes one name an alias of another. Every lookup for the alias, of any type, is answered by following the target instead. It's how you point www or shop at a service that gives you a host name rather than an address.

- Record type: CNAME
- Type number: 5
- Used for: Websites
- How common: Everyday
- Defined in: RFC 1034, RFC 1035, RFC 2181

## Format

```
<alias> <ttl> IN CNAME <target name>
```

| Field | What it means | Accepted values |
| --- | --- | --- |
| Name | The alias. It can't be the domain itself (@). | A subdomain such as `www`, `shop` or `_abc123.verify`. |
| TTL | How long resolvers may cache the alias. | Seconds. The target's own records have their own TTLs. |
| Target | The name the alias stands for. | A full host name, such as `shops.myshopify.com`. Not an IP address, not a URL with https:// or a path. |

## Examples

### www as an alias of the domain

```
www 3600 IN CNAME example.com.
```

www.example.com gets whatever addresses example.com has. Change the A record once and both names follow.

### Pointing at a hosted service

```
shop 3600 IN CNAME shops.myshopify.com.
```

The service can change its servers without you touching your DNS.

### Certificate or domain verification

```
_3f9a.example.com. 3600 IN CNAME _b72c.acm-validations.aws.
```

Many services verify ownership with an underscore CNAME. Keep it while the service needs to renew.

## The CNAME rules

- A name with a CNAME can't have any other record. Not an MX, not a TXT, not another CNAME. This is the rule people hit most.
- So a CNAME can't sit at the domain itself (@), because the domain always has SOA and NS records. Use an A record there, or [ALIAS / CNAME flattening](https://lemon.domains/dns-records/alias).
- MX, NS and SRV records must point at real names, not at CNAMEs.
- Chains (a CNAME pointing at another CNAME) work, but each step is another lookup. Keep them short; resolvers give up after about 8 to 16 steps.
- A CNAME redirects DNS lookups, not web traffic. The browser still sends the original name, so the target server must be set up to answer for it (which is why services ask you to add the domain in their dashboard too).

## CNAME is not a redirect

Pointing www at example.com with a CNAME doesn't change the address bar. Visitors stay on www.example.com and see whatever the server shows for that name. To send visitors from one address to another, set up an HTTP redirect on the web server or use your DNS host's redirect feature; registrars' "URL forwarding" works that way behind the scenes.

## TTL

3600 is fine for aliases you rarely change. Services that ask for a CNAME usually don't care about its TTL; their own records control how fast their changes spread.

## Common mistakes

- Adding a CNAME at the root (@). Most DNS hosts refuse; some accept it and break your email. Use ALIAS or an A record.
- Adding a CNAME at a name that already has a TXT or MX record, such as a CNAME at mail when mail also has an MX.
- Pointing a CNAME at an IP address. Use an A record for addresses.
- Putting https:// or a path in the target. A CNAME target is a bare host name.
- In a zone file, forgetting the final dot, so `shops.myshopify.com` becomes shops.myshopify.com.example.com.

## At your DNS host

- Cloudflare: allows a CNAME at the root and flattens it, answering with the target's addresses. Proxied CNAMEs answer with Cloudflare's addresses.
- Route 53: no CNAME at the root; use an Alias record for AWS targets.
- GoDaddy: www usually exists as a CNAME to @ already; edit it rather than adding a second one.
- Type the target as the full name. Dashboards add the trailing dot themselves.

## Questions

### Why can't I put a CNAME at the root of my domain?

A CNAME can't share its name with any other record, and the root of a domain always has SOA and NS records. Use an A record, or an ALIAS (CNAME flattening) record if your DNS host has one.

### Does a CNAME affect email?

Yes, if it's at a name that receives email: a CNAME hides every other record at that name, including MX. That's one more reason not to put a CNAME at the root.

### Is a CNAME slower than an A record?

Slightly, the first time: the resolver has to look up the target too. After that both answers are cached for their TTLs, so in practice the difference is milliseconds.

### Can a CNAME point to another domain?

Yes. That's the most common use: pointing your subdomain at a service on someone else's domain.

## Related

- [ALIAS and ANAME records](https://lemon.domains/dns-records/alias.md)
- [A record](https://lemon.domains/dns-records/a.md)
- [DNAME record](https://lemon.domains/dns-records/dname.md)
- [HTTPS record](https://lemon.domains/dns-records/https.md)
- [TXT record](https://lemon.domains/dns-records/txt.md)

Interactive version with a record checker and live lookup: https://lemon.domains/dns-records/cname
