19

What is the difference between a CNAME and a Subdomain?

I understand that the a cname (the left side of a domain) can point to the domain, so you can two different urls point to the same address, ie.

ex1.mydomain.com - if setup as a CNAME can return the IP of mydomain.com

If ex1.mydomain.com is setup as a subdomain, does it have a different IP?

Another question is what should the ideal setup be in this situation:

I have IP1:80 for a web app

I have IP2:80 for another app

Can I point both of these IPs to the same A record, with perhaps a different cname or subdomain?

Thanks for any help?

password
  • 293
  • 1
  • 2
  • 4

2 Answers2

33

A CNAME is a type of DNS record, where a hostname points at another hostname.

An A record is another type of DNS record, where a hostname points at an IP address.

A subdomain is what you described as 'the left side of the domain', e.g. webmasters.stackexchange.com is a subdomain of stackexchange.com. The DNS setup for a subdomain could use either an A record or a CNAME.

Your question:

Can I point both of these IPs to the same A record, with perhaps a different cname or subdomain?

doesn't really make sense. You don't point IPs at A records, you point hostnames at IPs using A records. If you're asking if you could point a domain and a subdomain at the same IP, the answer is yes.

This might be clearer with a real world example:

webmasters.stackexchange.com has an A record that points to the IP 198.252.206.140. stackexchange.com also has an A record that points to the IP 198.252.206.140.

It would therefore be possible to change webmasters.stackexchange.com to CNAME to stackexchange.com, and everything would continue to work as it does now.

(In practice, CNAMES are slightly slower than A records as they might result in an additional DNS lookup, so that's one reason why A records are more commonly used.)

Tim Fountain
  • 4,504
  • 1
  • 21
  • 19
-3

See comments for updated info -- This comment is most likely incorrect.

The answer above is not exactly accurate - if the the A Records were forwarded to the IP and the IP had virtual hosts setup they would be directed to different locations on the same server IP.

Changing it to a CNAME would most likely break this.

Ces
  • 1
  • 1