How to Add CNAME Record to DNS in Linux

How to Add CNAME Record to DNS in Linux

DNS (Domain Name System) is a crucial component of the internet that translates human-readable domain names into IP addresses, enabling seamless communication between devices. Adding a CNAME (Canonical Name) record to your DNS configuration is a common task, especially when you want to associate a subdomain with another domain. In this guide, we will walk you through the process of adding a CNAME record to DNS in a Linux environment.

Checking Your DNS Server:

Before you proceed, make sure you have administrative access to your DNS server. Common DNS servers in Linux include BIND (Berkeley Internet Name Domain) and dnsmasq.

Identifying the Domain:

Ensure that you know the domain for which you want to add a CNAME record. For example, if you want to create a CNAME record for "," you should have access to the DNS configuration for ""

Accessing the DNS Configuration Files:

Use a text editor like nano or vim to open the DNS configuration file. The file location can vary based on your DNS server. For BIND, it is often found in '/etc/bind/named.conf' or '/etc/bind/named.conf.local.'

sudo nano /etc/bind/named.conf.local

Adding the CNAME Record:

Once inside the configuration file, add the CNAME record in the following format:

subdomain IN CNAME targetdomain.

Replace "subdomain" with the desired subdomain and "targetdomain" with the domain to which the CNAME will point. Don't forget the trailing dot after the target domain.

Verifying the Syntax:

After adding the CNAME record, it's crucial to verify the syntax to avoid DNS configuration errors. Use the following command:

sudo named-checkconf /etc/bind/named.conf.local

Restarting the DNS Server:

Apply the changes by restarting your DNS server. The command varies based on your server, but for BIND, it's typically:

sudo service bind9 restart

Checking DNS Resolution:

Ensure the CNAME record is resolving correctly. You can use the 'dig' command to query the DNS:



If the resolution fails, double-check the syntax in the configuration file and verify that the DNS server is running.

More Examples:

Consider additional scenarios, such as creating CNAME records for different subdomains pointing to various target domains. Repeat the process for each record you need.

Related Searches and Questions asked:

  • How to Configure DNS Server in Linux CentOS 7
  • How to Configure DNS Server in Linux Ubuntu?
  • How to Add TXT Record to DNS Configuration in Linux?
  • How to Configure DNS Server?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.