Differences between the A and CNAME records

The A records are, together with the CNAME records, the most used ways to point any hostname to a specific IP address or more. While they share a similar function, there are a few differences between them that are important to know. Let’s take a look at this then.

First off, an A record is used to point a hostname to an IP address or more. Yes, you can point the same hostname to different IP addresses using more A records. If you want to point “mydomain.com” to the IP 1.1.1.1, then this would be your A record:

mydomain.com. 3600 IN A 1.1.1.1

Now let’s see what the CNAME record is about. CNAME records are used to point a hostname to another hostname. What’s different here? Well, in the A record we pointed the hostname to an IP (or more). The CNAME record is an alias of the target hostname and will get the same resolution chain that the target has. Let’s see an example of a CNAME point “mydomain.com” to “domain2.com”:

mydomain.com. 3600 IN CNAME domain2.com.

And now let’s see an example that uses both A records and CNAME records:

myshinydomain.com. 3600 IN CNAME mydomain.com
mydomain.com. 3600 IN A 2.2.2.2

What does this mean? First, myshinydomain.com is an alias of mydomain.com, and second mydomain.com is pointing to server 2.2.2.2, so in the end myshinydomain.com will be pointing to 2.2.2.2 too.

And that’s it. Like we said, A records are used to point a hostname to one IP or more, while CNAME records are used to point a hostname to another hostname, or to an A record depending on the resolution chain.



Leave a Reply