Trusted answers to developer questions

What is the difference between DNS A record and CNAME?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

DNS Illustration

Domain Name System (DNS) records are pieces of information hosted on DNS servers that provide details about domains.

A Records

An A record maps a domain or a subdomain to its server’s IP address.

The same domain or subdomain can be mapped to multiple IP addresses.

This is especially useful when you are trying to make your system fault-tolerant.

In order to make your system fault-tolerant, add multiple entries of the A records with the same domain or subdomain but different IP address values.

Here is an example of an A record:

DNS Records

As you can see in the above example, the A record is set to point to the IP address (119.165.10.1) whenever the user tries to access the website educative.io or drawing.educative.io.

CNAME record

A CNAME record maps a particular domain or subdomain to another hostname.

As you can see in the example above, the DNS points to educative.io whenever the user tries to access www or www.educative.io.

Getting IP for a website from DNS

Getting an IP address from DNS can be an iterative or a recursive process:

  • The user gets a CNAME record
  • The network makes another request to the DNS to get the records for the response for the previous query, in this case, educative.io.
  • The network keeps making queries until an IP address is returned. The above illustration explains this method.

Uses of CNAME

  • It provides different hostnames for different types of servers such as mail server, email server, etc.
  • Subdomains use the CNAME record to redirect users to the host domain.
  • By using CNAME records, you can redirect users to the most ideal server within their country such as google redirects users of the UK to google.co.uk

RELATED TAGS

general

CONTRIBUTOR

Sarvech Qadir
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?