You are currently viewing Difference Between DNS and CNAME

Difference Between DNS and CNAME

  • Post last modified:February 18, 2023
  • Reading time:8 mins read
  • Post category:Web Server

Definition of DNS and CNAME

DNS stands for Domain Name System and is a hierarchical decentralized naming system used to translate human-friendly domain names (such as www.example.com) into IP addresses (such as 192.0.2.1) that computers use to locate and communicate with each other.

CNAME, short for Canonical Name, is a type of DNS record that maps an alias domain name to its true or “canonical” domain name.

Purpose of DNS and CNAME

  • The purpose of DNS is to make it easy for people to find and access websites and other resources on the internet by using memorable domain names instead of IP addresses.
  • The purpose of CNAME is to allow multiple domain names to point to the same IP address and share the same website or other resource, making it possible to have multiple names for the same resource and also to easily change where a domain name points to.

DNS (Domain Name System)

A. How DNS works

  1.  When a user types a domain name into a web browser or other application, the client sends a request to a DNS server to resolve the domain name to an IP address.
  2.  The DNS server checks its own records to see if it has the IP address associated with the domain name. If it does, it returns the IP address to the client.
  3.  If the DNS server does not have the IP address in its records, it will forward the request to another DNS server, following the hierarchical structure of the DNS system, until the request reaches a server that has the IP address or it is determined that the domain name does not exist.

B. Types of DNS records

  1. A (Address) record: maps a domain name to an IPv4 address
  2.  AAAA (Address) record: maps a domain name to an IPv6 address
  3.  MX (Mail Exchange) record: specifies the mail server responsible for handling email for a domain
  4. CNAME (Canonical Name) record: creates an alias for a domain name, pointing it to another domain name
  5.  NS (Name Server) record: specifies the authoritative name servers for a domain
  6.  TXT (Text) record: can be used to store any text-based information associated with a domain name.

C. Examples of DNS usage

  1.  A user types “www.example.com” into their web browser, the browser sends a request to the DNS server to resolve the domain name to an IP address, the DNS server returns the IP address “192.0.2.1” and the browser uses that IP address to connect to the web server hosting the website for “www.example.com“.
  2.  An email is sent to “[email protected]“, the sending mail server looks up the MX record for “example.com” to determine which mail server is responsible for handling email for that domain, the mail is then sent to that server for delivery to the intended recipient.

CNAME (Canonical Name)

A. How CNAME works

  1. A CNAME record maps an alias or subdomain to its true or “canonical” domain.
  2. When a user types in the alias or subdomain in their browser or application, the client sends a request to the DNS server to resolve the domain name.
  3.  The DNS server checks its records and finds the CNAME record associated with the domain name, and returns the canonical domain name to the client.

B. How CNAME differs from other DNS records

  1. Unlike A and AAAA records, which map a domain name directly to an IP address, a CNAME record maps a domain name to another domain name.
  2.  CNAME record can’t coexist with other records like A, MX, NS, TXT etc on the same name.

C. Examples of CNAME usage

  1. A company has a website hosted on “www.example.com” and wants to create a subdomain “blog.example.com” to host their blog. They can create a CNAME record that maps “blog.example.com” to “www.example.com“, so that users can access the blog by either domain name.
  2.  A company wants to provide a vanity URL, such as “mycompany.com” to point to the actual website “www.mycompany.net” . A CNAME record can be created for “mycompany.com” that maps it to “www.mycompany.net“.

Differences between DNS and CNAME

A. Purpose and function

  1. The main purpose of DNS is to translate domain names to IP addresses, allowing users to access websites and other resources using human-friendly names. DNS also helps to distribute the load of traffic on the internet and make it more scalable.
  2. On the other hand, the main purpose of CNAME is to create aliases for a domain name, allowing multiple names to point to the same IP address and share the same website or resource. This allows for easy changes of where a domain name points to and also allows multiple names for the same resource.

B. How they are used together

  1. DNS is used to resolve domain names to IP addresses, while CNAME is used to create aliases that point to those domain names.
  2. CNAME records are often used in conjunction with other record types like A, MX, and NS to delegate authority and specify the IP addresses and mail servers associated with a domain name.

C. Best practices for using DNS and CNAME

  1. Use CNAME records to create aliases only for subdomains, not for the root domain.
  2.  Be cautious when using CNAME for the root domain, as it may cause issues with email, SSL, and other services that rely on the root domain having specific DNS records.
  3. Use CNAME for the purpose of load balancing or redundancy, not for changing IP addresses or hosting providers.
  4. Use DNS to delegate authority for subdomains to different name servers, if needed.

It’s worth noting that CNAME can be a bit more restrictive than other types of records. For example, a domain name with a CNAME record set cannot also have other types of records like MX, it’s important to be aware of these limitations when working with CNAME records.

Conclusion

  • DNS (Domain Name System) is a hierarchical decentralized naming system used to translate human-friendly domain names into IP addresses that computers use to locate and communicate with each other.
  • CNAME (Canonical Name) is a type of DNS record that maps an alias or subdomain to its true or “canonical” domain name.
  • The main purpose of DNS is to translate domain names to IP addresses, while the main purpose of CNAME is to create aliases for a domain name.
  • DNS and CNAME are used together to resolve domain names and create aliases for a domain name.
  • Best practices for using DNS and CNAME include using CNAME only for subdomains, being cautious when using CNAME for the root domain, using CNAME for load balancing or redundancy, and using DNS to delegate authority for subdomains to different name servers.

Additional resources for further learning

Leave a Reply