9

Let's suppose I have a domain which DNS contains 2 records:

  • a "A" record which contains an IP Address
  • a "CNAME" record which contains another domain (alias). Let's suppose this domain contains an IP to a second IP Address

My question is: Which one of the 2 IP Addresses will be answered if I ask a DNS resolution of my domain ?

Dave M
  • 4,494
Bob5421
  • 501

3 Answers3

6

You cannot have a CNAME record and other records for the same name.
If the scenario in the question is that you would have a CNAME record and an A record side by side, that is not really a concern since it is not possible.

2

Let's assume you have a server at IP address 111.111.111.111. You also have a domain called example.com. You can create an A record for example.com to point to 111.111.111.111.

The format that is used for a CNAME is [name] is an alias of [target].

So if you create a CNAME name: www.example.com to a target: example.com then www.example.com will do a redirect call for example.com, which will resolve to the IP address of 111.111.111.111.

CNAME resolves to A record

So basically when you create a CNAME you do not set another IP address, so you will only have one (the original A record) IP address to resolve to.

Original source of image: https://www.keycdn.com/support/what-is-a-cname-record

1

With regards to whether or not it is possible for this to happen, it is. Some DNS providers will alert you or provide an error not letting you to enter like this, but some DNS servers will in fact allow it even though it is technically incorrect 2.

To address the question itself, I will make the assumption with regards to your post that you are referring to a web request. Most browsers will first use their own cache and then rely on the OS's resolver to provide the internet address associated with the name you are requesting. Note also in the reference 2 that there are other request types that have different behaviours.

DNS itself does not care in what order the records are returned. Dare I use the term that has no place in the world of IT, "Random". The DNS server that is resolving the request may or may not have a configuration that allows sorting of the records returned. The server itself may or may not first resolve CNAMES to targets or A records. This is all dependent on the individual software that is running the DNS for the given zone. Here is an example of a DNS tool for microsoft DNS servers 1, you can see there is a flag to return records either ordered by the way they were entered into the database, or by IP address:

/localnetpriority [0|1] Determines the order in which host records are returned when the DNS server has multiple host records for the same name. Accepts the values: 0 - Returns the records in the order in which they're listed in the DNS database. 1 - Returns the records that have similar IP network addresses first. This is the default setting.

Some DNS server softwares also have settings for "round robin" approach, where it will iterate through records and return record one first, two second, three third etc.

In summary, it has been difficult for people to answer the question because it represents a case that is wrong by default and not RFC compliant 2. However, in the rare case you would come across this, since it is not compliant it is hard to say what the exact behaviour would be because there are too many variables determining the order of response from the DNS server... whose software is a variable in itself.

I truly hope this helps.

Kzin
  • 11