Hello friends,
I will show you how to configure DNS in CentOS 7
Linux. Let see How to configure BIND DNS Master server on CentOS 7.
DNS is used for name resolution.
DNS configuration is very useful to recognize your server
with FQDN in LAN and WAN. You can ping your server with server name with in LAN
(from any workstation) and WAN.
Following steps are useful to configure DNS.
Change HostName (give proper hostname with fully
qualified domain name)
Set hostname first (here my hostname is anand.linuxserver.com)
# vi /etc/hosts
127.0.0.1 localhost
localhost.localdomain localhost4 localhost4.localdomain4
::1
localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.105 anand.linuxserver.com
anand
# vi /etc/hostname
Here you type correct hostname (FQDN) Fully Qualified Domain Name.
Or
# nmtui à command for change hostname (easy
way)
Check you IP Address is correct or not and confirm.
# ifconfig
Here in this example my IP Address is 192.168.0.105 and Host Name
is anand.linuxserver.com
# ls –al /etc/sysconfig/network-scripts/
In this directory you will find ifcfg-eth0 or eno(some numbers)
linux nic card details that you can view using ifconfig command.
Now
bind packages installed.
What
is BIND in DNS ?
BIND (Berkely Internet Name Domain) is a popular software
for translating domain names into IP addresses and usually found on Linux
servers.
BIND's configuration consists of
multiple files,
yum install bind bind-utils
Confirm the prompt by entering
y
bind-9.9.4-51.el7_4.2.x86_64
bind-utils-9.9.4-51.el7_4.2.x86_64
bind-license-9.9.4-51.el7_4.2.noarch
bind-chroot-9.9.4-51.el7_4.2.x86_64
rpcbind-0.2.0-42.el7.x86_64
bind-libs-lite-9.9.4-51.el7_4.2.x86_64
bind-libs-9.9.4-51.el7_4.2.x86_64
Above packages are important and this will install by YUM.
YUM will resolved dependency error.
After installation of bind packages edit /etc/named.conf file.
Make few changes in the file as shown in below.
Here My IP ADDRESS is 192.168.0.105 and Hostname is
anand.linuxserver.com
# Vi /etc/named.conf
listen-on port 53 {
127.0.0.1; 192.168.0.105; };
#listen-on-v6 port 53
{ ::1; };
allow-query { localhost; 192.168.0.0/24; };
# allow-transfer{ localhost;
192.168.0.0/24; };
zone "linuxserver.com" IN {
type master ;
file "anand.zone" ;
allow-update { none;};
};
zone "0.168.192.in-addr.arpa" IN {
type master ;
file "anand.local" ;
allow-update { none; };
};
Save the file and exit, check the permission of file .
Permission should be 775 and owner, group should be root and
named.
Command is “chmod 775 /etc/named.conf “ ; chown root:named /etc/named.conf
Now nest step is very important be care full while typing.
Change the directory /var/named
# cd /var/named
List the files using command “ls –al” you will list the files and
directories.
Few files already present with DNS configuration contents .
Example :- named.ca, named.empty, named.localhost, named.loopback
Easiest method for to configure DNS with your own DNS name .
Copy named.localhost to yourDNSname.zone
In my example I have given anand.zone name is /etc/named.conf
file.
Make sure you are in /var/named directory
Here I am creating zone file, this would be a my forward zone file.
Command is à # cp
named.localhost anand.zone
Content of my file is as follows.
$TTL 1D
@ IN SOA anand.linuxserver.com.
root.anand.linuxserver.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H
) ; minimum
@
IN NS anand.linuxserver.com.
anand IN A
192.168.0.105
Save file and exit.
Now I creating reverse zone file
Copy file from same directory, command is à cp named.loopback anand.local
Open into editor and change with following contents .
$TTL 1D
@ IN SOA
anand.linuxserver.com.
root.anand.linuxserver.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H
) ; minimum
@ IN NS anand.linuxserver.com.
save and exit from this file.
Change the permission of the files.
# chmod 775 anand.zone anand.local
# chown named:named
anand.zone anand.local
Edit the file /etc/resolve.conf
# vi /etc/resolve.com à make few changes as mentioned below.
search linuxserver.com
nameserver 192.168.0.105
# named-checkzone anand.zone /var/named/anand.zone
# named-checkzone anand.local /var/named/anand.local
If the configuration is correct then you will get OK prompt
Now start the service of named
# systemctl enable named.service
# systemctl restart named.service
# firewall-cmd –permanent –add-port=53/tcp
# firewall-cmd –permanent –add-port=53/udp
# firewall-cmd --reload
Last command to check DNS is properly configured .
# dig anand.linuxserver.com
; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2
<<>> anand.linuxserver.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- 28031="" id:="" noerror="" o:p="" opcode:="" query="" status:="">->
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1,
ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;anand.linuxserver.com.
IN A
;; ANSWER SECTION:
anand.linuxserver.com.
86400 IN A
192.168.0.105
;; AUTHORITY SECTION:
linuxserver.com.
86400 IN NS
anand.linuxserver.com.
;; Query time: 0 msec
;; SERVER: 192.168.0.105#53(192.168.0.105)
;; WHEN: Thu Feb 01 21:29:46 IST 2018
;; MSG SIZE rcvd: 80
You will get similar output on screen.
Please remember in above output check the ANSWER section.
I hope this will help you to configure DNS.
Leave your comments or question if any I am appreciate your
feedback.
Cheers and good luck.