The key difference between CNAME and A record lies in how they map domain names to IP addresses:
1. A Record (Address Record):
- Purpose: Directly maps a domain name to an IPv4 address (e.g.,
192.168.1.1
). - Example:
example.com A 192.168.1.1
- In this case, when you type
example.com
in a browser, the DNS server returns the IP address192.168.1.1
. - Usage: Use an A record when you want to point a domain or subdomain to an IP address.
2. CNAME Record (Canonical Name Record):
- Purpose: Maps a domain name (alias) to another domain name, not directly to an IP address. This secondary domain is then resolved to its own A record (or IP address).
- Example:
www.example.com CNAME example.com
- In this case, when you type
www.example.com
, the DNS server looks up the IP address forexample.com
, and then returns that address. - Usage: Use a CNAME record when you want to alias one domain name to another, allowing multiple domains to point to the same underlying IP or service. Commonly used for subdomains like
www
.
Below is the few points to remember about CNAME and A record:
1) A record maps a hostname to an IP address.
2) The common use of the A record is to point a domain or hostname to an IP address.
3) Example of A record:
example.com A 1**.1**.3.2**
4) A record does not have this problem because it does not point to another domain name.
CNAME and A record:
1) CName record stands for Canonical Name. It is used in the DNS Zone to create an alias from one domain name to another domain name.
2) The common use of the CName record is when you run multiple services such as FTP, HTTP, and Mail service on the same machine and do not want to add IP addresses for each record. In that case, you can use Cname to point the FTP service to the http service without adding the IP address. For example, an FTP service has the domain name ftp.example.com, while an http service uses example.com. Since they are hosted on the same machine and using the same IP address, we can use the Cname record for ftp.example.com that points to example.com.
3) Example of a CNAME record:
ftp.example.com CNAME example.com
4) Improper CName records can result in an endless loop. For example, If you have added two CName records in the DNS Zone, such as ftp.example.com, which points to example.com, and in reverse, example.com points to ftp.example.com. Once you initiate the query, a CName record is found; having those two entries will result in an infinite loop that could crash the server.
Conclusion:
From the above summary you can easily understand about the key points about CNAME and A record.