×

A DNS is a database of the internet. When you enter a domain name on a web browser, the DNS is responsible for finding the IP address for the site.


Basically, a DNS server contains several public IP addresses.


Here at LinuxAPT, as part of our Server Management Services, we regularly help our customers to Install Software, and install DNS Server on their Server.


In this context, we will look into the process to take in order to configure DNS Server on CentOS 8.


How to configure BIND 9 DNS Server on CentOS 8?

In this guide, we shall set up a CentOS 8 machine as a DNS Server with a Static IP address lets say "192.168.10.10".

The other computers on the network will be configured in such a way that they would be able to access the DNS Server to resolve domain names.


How to Set up Static IP Address on CentOS 8?

To enable you set up a DNS Server it is very important to configure a static IP address on your CentOS 8 machine.

You can read our Complete guide on how to set up Static IP address on CentOS 8.


How to install DNS Server on CentOS 8?

You can get BIND 9 from CentOS 8 official package repository. 

To install it, start by updating the DNF package repository cache with the command below;


sudo dnf makecache


Next, proceed with the installation of Bind 9 with the command below;


sudo dnf install bind -y


Then Bind 9 will be installed successfully.



How to configure Bind 9 DNS Server?

Configuring Bind can be implemented via its main configuration file located at /etc/named.conf

Additionally, you can add your custom DNS databases in the directory "/var/named/". 

As soon as the DNS databases are created, then you can add your custom zone files in the directory "/etc/named/ ". 

The zone files can be included into the configuration file "/etc/named.conf".


Start by creating a DNS database for "linuxapt.local" domain name.


Then create a new file "db.linuxapt.local" in the "/var/named/" directory with the following command;


sudo vim /var/named/db.linuxapt.local


Then enter the following lines in the "db.linuxapt.local" file and save it after that;


$TTL 1d
$ORIGIN linuxapt.local.
@    IN   SOA  ns   root (
          2020031201 ; Serial
          12h        ; Refresh
          15m        ; Retry
          3w         ; Expire
          2h         ; Minimum
)
@    IN   A    192.168.10.10
@    IN   NS   ns
ns   IN   A    192.168.10.10
@    IN   MX   10   mail
mail IN   A    192.168.10.10
help IN   A    192.168.10.111
support    IN   A    192.168.10.112
www  IN   A    192.168.10.12
router     IN   A    192.168.2.1
ftp  IN   CNAME www



After adding a DNS database for linuxapt.local domain , Next, check if the syntax is correct with the command below;


sudo named-checkzone linuxapt.local /var/named/db.linuxapt.local


Next, create a zone file linuxapt.local.zones in the /etc/named/ directory for linuxapt.local domain with the command below;


sudo vim /etc/named/linuxapt.local.zones


Then add the following lines in the linuxapt.local.zones file as shown below and save the file followed by exiting it;


zone "linuxapt.local" IN {
    type master;
    file "db.linuxapt.local";
};



Next, modify the "/etc/named.conf" file with the command below;


sudo vim /etc/named.conf


Now you can add your network subnet to allow query (allow-query). This is to allow the computers in your network to be able to access the DNS Server otherwise none of the computers in your network will be able to use the DNS Server.


Lets say , the network subnet is "192.168.10.0/24" then the allow-query line in the "named.conf" file will look like this;


allow-query {localhost; 192.168.10.0/24; };


You can also add the IP address of your CentOS 8 machine you are working with as a DNS Server as listen-on address. So the listen-on line will look like this;


listen-on port 53 { 127.0.0.1; 192.168.10.10; };


Next, include the linuxapt.local.zones file from the /etc/named/ directory at the end of the /etc/named.conf file with the following line;


include "/etc/named/linuxapt.local.zones";


Now, you can start the "named" service with the following command;


sudo systemctl start named


If active, the named service should be running. Run the command below to know the status of the named service;


sudo systemctl status named


To enable the DNS Server to start automatically on boot, add the named service to the system startup of CentOS 8 with the command below;


sudo systemctl enable named


Whenever you make any changes to the DNS server configuration file after starting the named service, you must run the named service restart command stated below to enable it take effect;


sudo systemctl restart named


How to Test the DNS Server?

To test the DNS nameserver, you can simply use the "dig" tool.

To check if the DNS Server is listening on the outgoing network interface on CentOS 8, use the command below;


dig @192.168.10.10 linuxapt.local any


To check whether the DNS nameserver is accessible locally from within the CentOS 8 machine, use the command below;


dig @localhost linuxapt.local any


To check whether "www.linuxapt.local" resolves, run the command below;


dig @127.0.0.1 www.linuxapt.local


How to change the DNS Server Address of Network Interface?

To change the DNS Server address of your network interface to use the local DNS Server by default, you can read our Complete guide on how to set up Static IP address on CentOS 8 .


How to configure the Firewall for DNS Server on CentOS 8?

To allow DNS requests to be accessible via the firewall, simply open the DNS Server port 53 which is the default port for dns with the command below;


sudo firewall-cmd --add-service=dns --permanent


To make the changes to take effect, run the command below;


sudo firewall-cmd --reload


How to test the DNS Server of your CentOS 8 machine from other Computers?

Lets say a Windows 10 machine was configured on the same network as the CentOS 8 machine under the same network subnet to use the DNS Server, you can get the DNS to resolve for "linuxapt.local".


Need to configure BIND 9 DNS Server on CentOS 8? We are available to help you today.


Conclusion