what-is-dnswhat-is-dns

A Domain Name System (DNS) server is a network service that translates domain names into IP addresses, allowing computers to communicate with one another. In this article, we will cover how to set up a DNS server on CentOS 8.

Before starting, it is important to note that a DNS server typically consists of two components: a DNS server software, such as BIND, and a database that stores the DNS records. In this article, we will be using BIND as the DNS server software.

  1. Install BIND

To install BIND on CentOS 8, you will need to have the EPEL repository enabled. You can enable the EPEL repository by running the following command:

sudo dnf install epel-release

Next, update your package list and install BIND by running the following commands:

sudo dnf update
sudo dnf install bind bind-utils
  1. Configure BIND

BIND stores its configuration files in the /etc/named directory. The main configuration file is named.conf, which controls the overall behavior of the DNS server.

Before making any changes to the configuration file, it is a good idea to make a backup of the original file:

sudo cp /etc/named/named.conf /etc/named/named.conf.bak

Next, open named.conf in a text editor:

sudo vi /etc/named/named.conf

In the options section, you can specify the DNS server’s IP address and the port it should listen on. You can also specify the directory where the DNS records are stored:

options {
        directory       "/var/named";
        listen-on port 53 { any; };
        listen-on-v6 port 53 { any; };
};

Next, you will need to create a zone file for each domain that you want to serve. A zone file is a text file that contains the DNS records for a particular domain.

For example, to create a zone file for the domain example.com, you can run the following command:

sudo vi /var/named/example.com.zone

Inside the zone file, you can specify the DNS records for the domain. For example, to create an A record that maps the domain www.example.com to the IP address 192.0.2.1, you can add the following line to the zone file:

www IN A 192.0.2.1

After creating the zone file, you will need to include it in the named.conf file by adding the following line:

zone "example.com" IN {
        type master;
        file "example.com.zone";
};
  1. Start and enable BIND

To start BIND, run the following command:

sudo systemctl start named

To enable BIND to start automatically at boot, run the following command:

sudo systemctl enable named
  1. Test the DNS server

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

dig www.example.