Difference between cname and A record in DNS
CNAME (Canonical Name) and A (Address) records are two types of DNS records used to map domain names to IP addresses or other domain names. Here’s the difference between them:
-
A Record (Address Record):
- Purpose: Maps a domain name directly to an IP address (either IPv4 or IPv6).
- Usage Example: If you have a domain
example.com
and want it to point to a server with IP address192.0.2.1
, you'd use an A record. - How It Works: When someone visits
example.com
, the DNS resolver looks up the A record to find the IP address and directs the request to that server. - Example Record:
example.com. IN A 192.0.2.1
-
CNAME Record (Canonical Name Record):
- Purpose: Maps one domain name to another domain name (an alias).
- Usage Example: If you want
www.example.com
to point toexample.com
without needing to change the IP address for both, you'd use a CNAME. - How It Works: When someone visits
www.example.com
, the DNS resolver first looks up the CNAME record, which tells it to refer toexample.com
. Then it finds the IP address forexample.com
through its A record. - Example Record:
www.example.com. IN CNAME example.com.
Key Differences:
-
Direct vs Indirect Mapping:
- A records point directly to an IP address.
- CNAME records point to another domain name, which then resolves to an IP address.
-
Chaining of Domain Names:
- A records cannot point to another domain name.
- CNAME records create an alias for another domain name.
-
Use Case:
- Use an A record when you have a domain that you want to point to a specific IP.
- Use a CNAME when you want multiple domain names to point to the same domain, simplifying DNS management.
Published on: Oct 07, 2024, 11:48 PM