Configure DNS Server in Linux

How to Configure DNS Server in Ubuntu/Debian, CentOS/Fedora

Human beings understand words and machines understand codes. A communication bridge is required for creating the digital world. Domain Name Server is a server that builds this bridge to make words addressable for machines. In this article, you will learn How to Configure DNS Server in Ubuntu, Debian, CentOS, and Fedora. To have a server that assigns different numerical base addresses to be replaced with website alphabetical addresses, you must configure a DNS server on your system. So, all your IP addresses will be converted into FQDN and vice versa.

To manage and maintain your domain’s DNS records after buying Linux VPS, it makes sense to Configure DNS Server in Linux.

Reasons to Configure DNS Server You Should Know

The internet would be completely unusable without DNS servers. All of your online actions depend on the Domain Name System. Your experience may suffer as a result of any systemic issues. Your connection may actually slow down if the DNS servers provided by your ISP are slow or improperly set for caching. This is particularly true when a page loads that contains content from numerous distinct sources, like affiliates and advertisers. Whether you’re online at home or at work, switching to DNS servers that are more efficient will speed things up.

Some businesses provide DNS services with commercially advantageous add-ons. For instance, they are able to block harmful websites at the DNS level, preventing the pages from ever reaching a user’s browser. They could exclude websites that are improper for work. Similar to this, DNS-based parental control programs assist parents in limiting their children’s access to inappropriate content across all devices. Particular DNS servers concentrate on restricting access to risky websites and blocking dangerous web pages. Internet security is increased and vulnerability to online risks is decreased by changing the DNS setup to use such servers. Anyway, it is not that complicated to find a Trustable DNS server.

Some DNS servers keep track of web requests for marketing purposes. Online privacy can be better controlled by switching the DNS setup to a server that prioritizes privacy.  As you guess now, one of the essential and primary actions on your Linux server is to Configure DNS server in Linux. Stay with us in this article to find out how to do this in two different simple and quick methods.

Configure DNS Server in Linux (Ubuntu/Debian, CentOS/Fedora)

Previously, you learned How to Configure DNS Server in Windows Server. It is time to present an article for Linux users. Let’s go through this guide to review the best way you can Configure DNS server in Linux. In the end, you will be able to do the DNS server configuration in Ubuntu, Debian, CentOS, and Fedora.

Method 1. Configure DNS Server in Linux Using Command Line

Open your Terminal (CTRL + ALT + T) and follow the below steps to configure the critical component of your network infrastructure.

Step 1. Installing DNS Server

As the beginning action, you need to install the DNS server on your current Linux distribution. Since BIND (Berkeley Internet Name Domain) is the typically used server in Linux, use the following command to install it first. Before that, you are recommended to update your system.

$ sudo apt update

On Debian/Ubuntu:

sudo apt-get install bind9

On Redhat/CentOS/Fedora:

# yum install bind9

The main configuration file, /etc/bind/named.conf, contains all other necessary files.

Step 2. Install DNS Utilities

After installing the DNS server on your system, you can run the command below to install the utilities of the DNS.

$ sudo apt install dnsutils

Step 3. Configure DNS Server

In this step, you can do the configuration on your DNS server. The configuration files for BIND are stored in the /etc/bind directory. Open the named.conf file using a text editor and make the following modifications:

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

By now, the recursion has been enabled and trusted clients are permitted to run recursive queries. Additionally, Google’s public DNS servers are added as forwarders and made the DNS server listen on all interfaces.

The simple-to-remember IP addresses and are used by Google Public DNS, which has been available since 2009. Among other things, Google guarantees a performance boost and a secure DNS connection that is fortified against assaults.

What is Cache NameServer and Why Use it?

A DNS caching server’s function is to make queries of other DNS servers and cache the results. When the identical question is submitted again later, it will return the cached response. Periodic updates will be made to the cache. Although you can set up bind to function as both a Primary and a Caching server, it is not advisable to do so for security reasons. A separate caching server should be used.

It only requires adding your ISP’s DNS server or any OpenDNS server to the file /etc/bind/named.conf.options to configure a Cache NameServer. The public DNS servers and of Google were used as an example in the above example.

Step 4. Create DNS Zones

An area of the DNS namespace known as a DNS zone is one for which a specific DNS server is in charge. Make a file in the /etc/bind directory with the domain name in it to create a DNS zone. For example, create a file called /etc/bind/ with the following information if the domain name is

$TTL 86400
@ IN SOA (
        38400 )
@ IN A
ns1 IN A
ns2 IN A

In this way, the domain’s SOA record is established, and two NS entries for the DNS servers are added. Additionally, two A records for the DNS servers and an A record for the domain have been added. Lastly have included a CNAME record for the www subdomain.

Step 5. Restart DNS Server

To enable the configuration, run the following command to restart the DNS:

$ sudo systemctl restart bind9Step 6.0 

Step 6. Test DNS Server

After making any modifications, don’t forget to test your DNS server to make sure everything is working as it should. You can check its status by running the command below:

$ sudo systemctl status bind9

While bind9 is currently operating, test the domain that you modified as follows in the configuration file:

$ dig

If you dig twice, you will see the Query time would be improved the second time. Configure DNS server in Linux is finished here. If you view the IP address of the domain in your output, all is correct.

Method 2. Configure Master NameServer for Your Zone

So far, you reviewed all the required steps to Configure DNS server in ubuntu, debian, centos and fedora. Now, you are ready to Configure the primary zone using Terminal. The DNS gets its data for each zone from a specific file that was stored on a particular host. To see if the following three instructions are there and uncommented, open your proffered editor for primary configuration:

include “/etc/bind/named/.conf.option”;

include “/etc/bind/named/.conf.local”;

include “/etc/bind/named/.conf.default-zones”;

Open the editor to verify:

$ sudo vi /etc/bind/named.conf

You must view all three lines in your output. To configure your considered domain (For example, edit the file named.conf.local by opening as:

$ sudo vi /etc/bind/named.conf.local

Now, edit the following text in the editor like below:

zone “operavpscom” {

type master;

file “/etc/bind/”;


Then, you need to copy the contents from the db.local to the

$ sudo cp /etc/bind/db.local /etc/bind/

To make changes effect, restart the DNS by running:

$ sudo systemctl restart bind9

At this point, establish a reverse zone file in order for our newly created domain “” to communicate with a certain IP address. In order to achieve this, we will additionally configure the reverse zone file as follows:

$ sudo vi /etc/bind/named.conf.local

And add the following text:

zone “Your first network” {

type master;

file “/etc/bind/db.10”;


Keep in mind to replace your own octets in the above command. Then, copy and create the new file with db.10 as:

$ sudo cp /etc/bind/db.127 /etc/bind/db.10

When you open the created file, the output displays as:

$ sudo vi /etc/bind/db.10

In this final section, we will verify the configurations by running all of these commands and determining whether or not they result in errors:

$ named-checkzone /etc/bind/

$ named-checkzone Your IP /32 /etc/bind/db.10

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

$ named-checkconf /etc/bind/named.conf

If you receive no error after running the above commands, it means that your DNS has been configured successfully. However, it is possible to Change DNS Server Settings in Linux if you need to.


All DNS settings are kept in the /etc/bind directory.

It is not advisable to configure bind to function as both a Primary and a Caching server for security reasons. It is advised to have a different caching server.


In this article, you learned How to Configure DNS Server in Linux. Two different methods were explained to let you understand better and choose the one you prefer. In the first method, you learned how to configure a domain using the command line and test it which was Google domain in this guide. Using the terminal method, you reviewed how to forward and reverse file zone configuration. To do this, you created a domain of

If you follow the above steps properly then you can smoothly configure DNS server in Ubuntu/Debian, CentOS/Fedora without any errors but do not hesitate to contact us if you encounter any problems. Our technical support team will try their best to solve your problems.

If you know any other methods to configure DNS server in Linux, then the comment section is all yours.

Related Article : What is Debian OS

Leave a Reply

Your email address will not be published. Required fields are marked.