Installing and Configuring a DNS Server
In Linux, the most used DNS server is bind (short for Berkeley Internet Name Daemon), which can be installed as follows:
# yum install bind bind-utils [CentOS] # zypper install bind bind-utils [openSUSE] # aptitude install bind9 bind9utils [Ubuntu]
Once we have installed bind and related utilities, let’s make a copy of the configuration file before making any changes:
# cp /etc/named.conf /etc/named.conf.orig [CentOS and openSUSE] # cp /etc/bind/named.conf /etc/bind/named.conf.orig [Ubuntu]
Then let’s open named.conf
and head over to the options block, where we need to set make sure the following settings are present to configure a recursive, caching server with IP 192.168.0.18/24 that can be accessed only by hosts in the same network (as a security measure).
The forwarders settings are used to indicate which name servers should be queried first (in the following example we use Google’s name servers) for hosts outside our domain:
options { ... listen-on port 53 { 127.0.0.1; 192.168.0.18}; allow-query { localhost; 192.168.0.0/24; }; recursion yes; forwarders { 8.8.8.8; 8.8.4.4; }; … }
Outside the options block, we will define our sales.me.com
zone (in Ubuntu this is usually done in a separate file called named.conf.local) that maps a domain with a given IP address and a reverse zone to map the IP address to the corresponding domain.
However, the actual configuration of each zone will go in separate files as indicated by the file directive (“master”
indicates we will only use one DNS server).
Add the following blocks to named.conf
file:
zone "sales.me.com." IN { type master; file "/var/named/sales.me.com.zone"; }; zone "0.168.192.in-addr.arpa" IN { type master; file "/var/named/0.162.192.in-addr.arpa.zone"; };
Note that in-addr.arpa
(for IPv4 addresses) and ip6.arpa
(for IPv6) are conventions for reverse zone configurations.
After saving the above changes to named.conf, we can check for errors as follows:
# named-checkconf /etc/named.conf
If any errors are found, the above command will output an informative message with the cause and the line where they are located. Otherwise, it will not return anything.
There are 2 typos (well two digits transposed) in the sample reverse DNS zone example given above.
Here’s the text provided:
The file directive has the 2 and the 8 transposed. The file name should be “/var/named/0.168.192.in-addr.arpa.zone“
@BJ,
Thanks, I have corrected the file in the article…
Hi Gabriel Cánepa,
could you help me here..?
https://serverfault.com/questions/930206/centos6-9-not-possible-to-resolv-two-windows-domain-controllers-at-a-time-using
Hello Mr Canepa,
First of all I would like to thank you for a very good articles in order to help me to prepare for LFCS. I studied all of them very carefully, but unfortunately I was stuck at the DNS.
It is about 3th part of this chapter. I don’t know if files /var/named/sales.me.com.zone and /var/named/0.168.192.in-addr.arpa.zone should be appeared automatically or should I append them on my own?
There are differences between CentOS and Ubuntu because of location of these files – in Ubuntu these files supposed to be in /var/cache/bind…
I will be thankful for your support.
Hello again,
I would like to inform that all questions mentioned above I solved. I just created require zone-files in /etc/bind/.
Unfortunately I met another issue and I tried to handled with that all the day – without result. When I try to check the answer with host command I received always the same error: “Host ….. not found: 3(NXDOMAIN)“.
The zone files and option files are done correctly without any errors.
Could someone help me with that and point me where I should looking for a mistake..? Many thanks in advance.
Radek.