What is a Cname?
CNAME or Canonical Name Record is a term utilized in the DNS (Domain Name System) to create an alias from one domain name to another. A commonly seen example is the www subdomain which is provided as an alias to the original domain name – users accessing “www.example2.com” are redirected to the root domain (or DNS zone apex) “example2.com” thanks to the alias.
How does a Cname work?
When a browser (or any internet client) looks up a hostname, it’ll first check to see if the host has an Address record or an IPv6 Address record. If it finds one of those, it will now have an IP to connect to that host and request the web page.
However, if the client doesn’t find an Address record or an IPv6 Address Record, it’ll next check for a Canonical Name (CNAME) record. If there is a CNAME, it’ll be in the form of a different hostname, not an IP address. The client will then look for an Address Record, IPv6 Address record, and CNAME records for the new hostname.
This sequence will repeat until the client gets an Address record or fails to find any records. (It should be noted that while chaining together CNAMEs is legal, it’s up to the client how many levels it will recourse, and each lookup will slow down the eventual resolution of the final IP address.)
In the case of an internet browser, it will send an HTTP request to the resulting IP address found and set a Host header to the original hostname found. This will allow the webserver to know the name of the host the user originally wanted.
Most of the commonly used DNS server software does not allow any other records to exist for a host with a CNAME record. If, for some reason, a DNS server manages to find a way to have both a CNAME record and another record, clients will ignore the extra records. Due to this reason, having a CNAME of your domain name is not something to look forward to and is usually avoided.
In which cases the Cname is used?
There are several and common cases where the CNAMErecords are used, since conflicts where CNAMErecords need to be utilized happen all the time; these situations can be said to be common:
- Cname records are used when registering the same domain in different countries and pointing the versions from other countries to the original “.com” domain
- When directing from different websites owned by the same parent organization to a primary website
- Many hosting services give away a subdomain for each customer on the hosting services’ domain (for example, group.hostname.com) and use CNAME to direct to the customer’s domain (www.group.com).
Examples of CNAMES.
An easily understood example of CNAME record can be this, mapping the web address www.example1.com to the actual website for the domain example1.com.
This means that www.example1.com and example1.com are connected to each other thanks to the CNAMErecord.