All website or resources on the internet mostly uses meaningful URLs to locate themselves but we must know that behind the scenes, these resources have IP addresses assigned. & basically these IP addresses are used to locate the website's servers. So how does a meaningful URL translates into an IP address, for that DNS is used.

In this tutorial, we will learn to install DNS on CentOS 8 / RHEL 8 & also its configuration. But first, let’s discuss a bit about DNS itself & some of its related terminology.

DNS

DNS (short for Domain Name System) is a service that translates an IP address into domain name & vice-versa. In an environment with only a limited number of Linux machines, we can make entries in /etc/hosts file for associating an IP address with a name but when you have a large infrastructure with lots and lots of systems/resources, /etc/hosts will not work. For these kinds of scenarios, we implement BIND (DNS) in our environment.

BIND or Berkeley Internet Name Domain is the most widely used Open source software that implements DNS protocols for the internet, which provides usability to implement IP to domain name conversion & vice-versa.

In this tutorial, we will learn to implement the BIND (DNS) server in our local environment. But before we do that there are some DNS records that we need to be aware of. Although there are a number of DNS records, we will only discuss some of the important ones which will be used in this tutorial.

DNS records

  • A record                                                       is used to map the hostname to an IP address
  • NS (Name server) record                        identifies authoritative DNS server for the zone
  • MX (mail exchanger) record                   specifies a mail server responsible for accepting of mail in the zone
  • CN (canonical name) record                   specifies the alias of one name to another name,
  • PTR (Pointer) record                                are reverse DNS record i.e. from IP address to hostname
  • SOA (Start of Authority)                          record contains information about DNS zones & other DNS records.

So lets start with how to install DNS on CentOS 8 & RHEL 8,

 

Recommended Read: Setting up MASTER SLAVE DNS setup with BIND

Also Read: Managing network connections using IFCONFIG & NMCLI commands

 


Installation

As mentioned earlier, we will use BIND to implement the DNS, so we need to install bind & related packages on the system,

# yum install bind bind-utils

Note:- With CentOS 8, you can also use the dnf package manager to install packages on your server.

Once the packages have been installed, we will move onto the configuration of DNS.


Configuration

Configuration file for DNS is located at /etc/named.conf, so now we need to make changes to this file,

# vim /etc/named.conf

First, we need to allow BIND service to listen from all IP addresses, so to do that we need to comment on the following lines,

#listen-on port 53 { 127.0.0.1; };

#listen-on-v6 port 53 { ::1; };

Or if we need to allow a particular network or IP addresses, we can replace 127.0.0.1 with those. Next, we need to add our network IP range to allow incoming queries to DNS server, so add the following line in the same file,

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

install DNS on centos 8

Replace 10.10.1.0/24 with your network IP range.  Next step is to add the location of forward & reverse zone files location in the named.conf only,

zone “linuxtechlab.localdomain" IN {

type master;

file "forward.ltechlab”;

allow-update { none; };

};

zone "1.10.10.in-addr.arpa" IN {

type master;

file "reverse.ltechlab”;

allow-update { none; };

};

install dns on centos 8

That’s all the configuration needed on /etc/named.conf file. Now save the file & exit out of editor.

We have mentioned the locations of forward & reverse zones files but we are yet to create them, so next step would be to create those files. We will start with forward zone file first,

# vim /var/named/forward.ltechlab

& add the following lines,

$TTL 86400

@ IN SOA primary.linuxtechlab.localdomain. root.linuxtechlab.localdomain. (

2011071001 ;Serial

3600 ;Refresh

1800 ;Retry

604800 ;Expire

86400 ;Minimum TTL

)

@ IN NS primary.linuxtechlab.localdomain.

@ IN A 10.10.1.10

primary IN A 10.10.1.10

Save the fil & exit. Now let’s create reverse zone with the following content,

# vim /var/named/reverse.ltechlab

$TTL 86400

@ IN SOA primary.linuxtechlab.localdomain. root.linuxtechlab.localdomain. (

2011071001 ;Serial

3600 ;Refresh

1800 ;Retry

604800 ;Expire

86400 ;Minimum TTL

)

@ IN NS primary.linuxtechlab.localdomain.

@ IN PTR linuxtechlab.localdomain.

primary IN A 10.10.1.10

152 IN PTR primary.linuxtechlab.localdomain.

That’s it, save the file & exit from editor. We now have made all the changes required to install DNS on CentOS 8 & RHEL 8, also we have made the configuration changes as well.  Now all we need is to restart the DNS service to implement all the changes,

# systemctl restart named

We can also enable it for boot time,

# systemctl enable named


Testing DNS

To test the DNS, we need to configure the DNS IP address i.e. 10.10.1.10 in the IP configuration & also make to make entry in ‘/etc/resolv.conf’ file,

# vim /etc/resolv.conf

nameserver  10.10.1.10

Now restart the network manager to implement these changes to DNS on the client system,

# systemctl restart NetworkManager

Now we can the DNS service using the DIG command,

# dig primary.linuxtechlab.localdomain

install dns on centos 8

& we should receive output like following,

So we now have a working DNS server & we can add more servers to it for DNS name resolution. All we have to do it to add A RECORD in forward lookup zone file & POINTER RECORDS in reverse lookup zone,

# vim /etc/named/forward.ltech

& add entries like following to the bottom of the file,

;A Record for IP address to Hostname

mail IN A 10.10.1.11

www IN A 10.10.1.12

www IN A 10.10.1.20

Save file & exit, next add pointer records to reverse zone file (at bottom),

# vim /etc/named/reverse.ltechlab

5 IN PTR mail.ltechlab.local.

10 IN PTR www.ltechlab.local.

20 IN PTR www.ltechlab1.local.

That’s it, after saving both files we need to restart the DNS service to implement the changes,

# systemctl restart named

Now we will also be able get the DNS resolution for added hosts as well. We now end this tutorial on how to install DNS on CentOS 8 & RHEL 8. Please do let us know, if you have any questions or queries.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Donate us some of your hard-earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.