Home  Web-development   Difference ...

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:

  1. 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 address 192.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
      
  2. 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 to example.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 to example.com. Then it finds the IP address for example.com through its A record.
    • Example Record:
      www.example.com.    IN    CNAME    example.com.
      

Key Differences:

Published on: Oct 07, 2024, 11:48 PM  
 

Comments

Add your comment