Header Ads

How to Configure DNS Server in Linux Step by Step?

How to Configure DNS Server in Linux Step by Step

Domain Name System (DNS) is a critical component of any network infrastructure, which helps in resolving domain names to IP addresses. A DNS server is responsible for managing and maintaining the DNS records for a domain. In this article, we will discuss how to configure a DNS server in Linux step by step.

Step 1: Install the DNS Server

The first step is to install the DNS server on your Linux machine. The most common DNS server used in Linux is BIND (Berkeley Internet Name Domain). You can install BIND using the following command:

sudo apt-get install bind9

Step 2: Configure the DNS Server

Once the DNS server is installed, the next step is to configure it. The configuration files for BIND are located in the /etc/bind directory. The main configuration file is named named.conf. Open the named.conf file using a text editor and make the following changes:

options {
directory "/var/cache/bind";
recursion yes;
allow-recursion { trusted; };
listen-on { any; };
allow-transfer { none; };
forwarders {;;

Here, we have enabled recursion and allowed trusted clients to perform recursive queries. We have also enabled the DNS server to listen on all interfaces and have added Google's public DNS servers as forwarders.

Step 3: Create DNS Zones

A DNS zone is a portion of the DNS namespace for which a particular DNS server is responsible. To create a DNS zone, create a file named after the domain name in the /etc/bind directory. For example, if the domain name is example.com, create a file named /etc/bind/db.example.com with the following contents:

$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (

@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
@ IN A
ns1 IN A
ns2 IN A
www IN CNAME example.com.

Here, we have defined the SOA record for the domain and added two NS records for the DNS servers. We have also added an A record for the domain and two A records for the DNS servers. Finally, we have added a CNAME record for the www subdomain.

Step 4: Restart the DNS Server

After making changes to the configuration files, you need to restart the DNS server for the changes to take effect. You can do this using the following command:

sudo systemctl restart bind9

Step 5: Test the DNS Server

To test the DNS server, you can use the dig command. For example, to resolve the IP address of example.com, use the following command:

dig example.com

If everything is configured correctly, you should see the IP address of the domain in the output.

Configuring a DNS server in Linux may seem daunting at first, but it is essential for any network infrastructure. By following the steps outlined in this article, you should be able to configure a DNS server in Linux with ease. Remember to test your DNS server after making any changes to ensure that it is functioning correctly.

Related Searches and Questions asked:

  • How to Create DNS Server in CentOS?
  • How to Configure Primary and Secondary DNS Server in Linux?
  • How to Set DNS Server in Linux Ubuntu?
  • How to Find DNS on Linux Command?
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.

    Powered by Blogger.