Difference between CNAME and A records!

February 10, 2023


CNAME (Canonical Name) records are used to map an alias or subdomain to a real or target domain name. For example, you might use a CNAME record to map the hostname “www.example.com” to the target domain “example.com”.

Here’s an example of a CNAME record:

www.example.com. IN CNAME example.com.

In this example, the CNAME record maps “www.example.com” to “example.com”. So, when a user visits “www.example.com“, the server will return the same content as it would for “example.com”. This can be useful for hosting multiple subdomains on a single server, or for redirecting traffic to a different server without changing the URL in the user’s browser.

A (Address) records, on the other hand, map a domain name to an IP address. For example, you might use an A record to map the domain name “example.com” to the IP address “192.168.1.100”.

Here’s an example of an A record:

example.com. IN A 192.168.1.100

In this example, the A record maps “example.com” to the IP address “192.168.1.100”. So, when a user visits “example.com”, their browser will connect to the server at IP address “192.168.1.100” to retrieve the content for the website.

It’s important to note that CNAME records cannot be used for the root domain (e.g., “example.com”), as the root domain must be mapped to an IP address using an A record. Additionally, CNAME records can’t be used in combination with other record types for the same hostname, as this can lead to conflicts and unexpected behavior.

ANOTHER EXAMPLE:

dev.website.com.au.                      14400                   A                             100.1.100.100

www.dev.website.com.au.          14400                   CNAME                 dev.website.com.au