Differences Between A and CNAME Records #
A (Address) Record:
- The A record points a hostname directly to an IP address.
- It is used to map a domain (e.g., blog.dnsimple.com) to the IP address of a server (e.g., 185.31.17.133).
- Example:
blog.dnsimple.com. A 185.31.17.133
- A records are ideal for situations where you need to link a domain directly to an IP address, which is the location of the server that will host the website.
CNAME (Canonical Name) Record:
- The CNAME record points a hostname to another hostname, not directly to an IP address.
- This means the CNAME record is essentially an alias for another domain, and it will resolve based on the target domain’s own DNS resolution process.
- Example:
blog.dnsimple.com. CNAME aetrion.github.io. - aetrion.github.io. CNAME github.map.fastly.net.
- github.map.fastly.net. A 185.31.17.133
- Here, blog.dnsimple.com points to aetrion.github.io, which in turn points to github.map.fastly.net, and ultimately the A record for github.map.fastly.net resolves to the IP 185.31.17.133.
Key Differences: #
- Target:
- A Record points directly to an IP address.
- CNAME Record points to another hostname (which may ultimately resolve to an IP via A record).
- A Record points directly to an IP address.
- Usage:
- Use an A record if you need to map a domain directly to an IP address (e.g., website hosting).
- Use a CNAME record when you want to alias one domain to another, especially useful for services like GitHub Pages, subdomains, or third-party services.
- Use an A record if you need to map a domain directly to an IP address (e.g., website hosting).
- Resolution Process:
- An A record resolves to an IP address directly.
- A CNAME record resolves to another domain, which could have its own A record pointing to an IP address.
- An A record resolves to an IP address directly.
Example Scenario: #
- A Record:
If example.com is hosted on the server at IP 192.168.1.1, you will use:
example.com. A 192.168.1.1
- CNAME Record:
If you want to use a subdomain (e.g., blog.example.com) to point to a third-party service (like GitHub Pages), you can use:
blog.example.com. CNAME yourgithubusername.github.io.
Which One to Use: #
- A Record: When you have a specific IP address to point your domain to.
- CNAME Record: When you want to alias one domain name to another, and it allows for easier management when the target domain changes its IP address.