What is a DNS CNAME record?
There are several types of records - or Resource Records as they are called - in the Domain Name System (DNS). This page explains what the CNAME record is and how it's used.
The purpose of a DNS CNAME record
The CNAME record is a special kind of DNS record. If can be looked at as an alias or - in Linux terms - a symlink to another record.
A CNAME isn't just an alias for a single record type, but for the entire host that it applies to. Let's explain that when diving into the structure of a CNAME record next.
The structure of a DNS CNAME record
This is an example of a CNAME record:
www.ohdear.app. 60 IN CNAME ohdear.app.
With this, we have instructed that every DNS lookup for www.ohdear.app
should be forwarded to ohdear.app
instead. As a result, when a client (ie: your webbrowser) wants to resolve www.ohdear.app
, it will make another DNS query to ohdear.app
and use that response as the canonical value (= CNAME) of the www.
-subdomain.
The structure is similar to A or CNAME records:
<host> <TTL> IN CNAME <domain-name>
A CNAME must point to another domain name, never to an IP address.
Special notes on DNS CNAME records
This kind of record can be a little confusing. There's one important note on CNAME records, and that is that once you define a CNAME record for a host record, no other record can be present.
For instance, this isn't allowed:
www.ohdear.app. 60 IN CNAME ohdear.app.
www.ohdear.app. 60 IN MX 10 mailserver.ohdear.app.
www.ohdear.app. 60 IN TXT "google-site-verification=123".
Because a CNAME was issued for www.ohdear.app
, you cannot define a MX or TXT record.
Instead, the CNAME instructs every other resource record to be found at the target (in this case: ohdear.app
) instead.
If you were to request the MX record for www.ohdear.app
in the above example, you would get back the MX record defined at the CNAME target instead: ohdear.app
. This is why there can be no overlap with CNAME records.
Was this page helpful to you? Feel free to reach out via support@ohdear.app or on Twitter via @OhDearApp if you have any other questions. We'd love to help!