Install & Configure the BIND DNS Server

 

Install & Configure the BIND DNS Server

Install BIND

1. Make sure you have internet connectivity and install the BIND DNS server.

[root@centos#]yum install bind

2. Set your DNS server setting to resolve to your loopback interface. Edit the configuration of you interface.

[root@centos#]vi /etc/sysconfig/network-scripts/ifcfg-eth0

# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
NM_CONTROLLED=”no”
DNS1=127.0.0.1
BOOTPROTO=static
BROADCAST=192.168.2.255
GATEWAY=192.168.2.254
HWADDR=00:00:00:00:00:00
IPADDR=192.168.2.124
NETMASK=255.255.255.0
NETWORK=192.168.2.0
ONBOOT=yes
NETWORKING_IPV6=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes

After the changes, make sure that you have executed the command below.

[root@centos sysconfig]#ifdown eth0
[root@centos sysconfig]#ifup eth0

3. Check the resolve.conf file to verify that your DNS setting of 127.0.0.1 is available. This should automatically be reflected to resolv.conf file. DO NOT manually type the loop back address to the resolv.conf.

cat /etc/resolv.conf

4. Restart the BIND DNS server.

[root@centos sysconfig]#service named restart

5. Now try to see if your DNS server can reach other DNS servers over the internet in order to resolve dns lookups.
nslookup google.com

6. Now put in a chkconfig command to allow BIND to start on system startup.

[root@centos sysconfig]#chkconfig named on

7. I have assigned my hostname to “centos”.

[root@centos sysconfig]# vi /etc/sysconfig/network
and add the following line after NETWORKING=”yes”:
HOSTNAME=”example-server-hostname”

8. Add a fully qualified domain name (FQDN).

[root@centos sysconfig]#vi/etc/sysconfig/network-scripts/ifcfg-eth0

# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
NM_CONTROLLED=”no”
DOMAIN=”centos.com”
DNS1=127.0.0.1
BOOTPROTO=static
BROADCAST=192.168.2.255
GATEWAY=192.168.2.254
HWADDR=00:00:00:00:00:00
IPADDR=192.168.2.124
NETMASK=255.255.255.0
NETWORK=192.168.2.0
ONBOOT=yes
NETWORKING_IPV6=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes

9. Now that your hostname and fully qualified domain name are configured it is time to configure the BIND (NAMED) DNS server.The first file to configure is: /etc/named.conf

[root@centos sysconfig]#vi /etc/named.conf

acl local-network { 192.168.2.0/24; };
options
{
listen-on { any; };
allow-query {any;};
allow-recursion { 127.0.0.1; };
query-source port 53;

directory “/var/named”; // the default
dump-file “data/cache_dump.db”;
statistics-file “data/named_stats.txt”;
memstatistics-file “data/named_mem_stats.txt”;
};
logging
{
channel default_debug {
file “data/named.run”;
severity dynamic;
};
};

view “internal”
{
match-clients {localnets; 127.0.0.1; 192.168.2.0/24;};
match-destinations {localnets; 127.0.0.1; 192.168.2.0/24;};
// recursion yes;
include “/etc/named.root.hints”;
include “/etc/rndc.key”;
include “/etc/named.rfc1912.zones”;

zone “centos.com” IN {
type master;
file “/var/named/centos.com.zone.db”;
allow-update { none;};
};

zone “siteone.com” IN {
type master;
file “/var/named/siteone.com.zone.db”;
allow-update { none;};
};

zone “sitetwo.com” IN {
type master;
file “/var/named/sitetwo.com.zone.db”;
allow-update { none;};
};

zone “2.168.192.in-addr.arpa” IN {
type master;
file “/var/named/centos.com.zone.rr.db”;
allow-update { none; };
};

zone “abc.com” IN {
type master;
file “/var/named/abc.com.zone.db”;
allow-update { none;};
};

zone “3.2.1.in-addr.arpa” IN {
type master;
file “/var/named/abc.com.zone.rr.db”;
allow-update { none; };
};

};

11. Create two zone reference file to this location /var/named/chroot/var/named/

—-This is for my domain name “centos.com” —–
centos.com.zone.db
centos.com.rr.zone.db
————————————————-

/********centos.com.zone.db starts here*******/

$ORIGIN centos.com.
$TTL 86400
@ IN SOA dns1.centos.com. hostmaster.centos.com. (
2012112901
21600
3600
604800
86400 )
IN      NS      dns1.centos.com.
IN      MX      10 mail.centos.com.
IN      A       192.168.2.124
dns1    IN      A       192.168.2.124
centos  IN      A       192.168.2.124
ftp     IN      A       192.168.2.124
mail    IN      CNAME   centos.
www     IN      CNAME   centos.

/********centos.com.zone.db ends here*******/

/******centos.com.zone.rr.db starts here****/

$ORIGIN 2.168.192.IN-ADDR.ARPA.
$TTL 86400
@       IN      SOA     dns1.centos.com. hostmaster.centos.com. (
2012112901
21600
3600
604800
86400 )

@       IN      NS      dns.centos.com.
1       IN      PTR     centos.centos.com.
2       IN      PTR     centos.centos.com.
3       IN      PTR     centos.centos.com.
4       IN      PTR     centos.centos.com.

/*******centos.com.zone.rr.db ends here*****/

—-This is for my domain name “abcd.com” —–
abc.com.zone.db
abc.com.rr.zone.db
———————————————–

/********abc.com.zone.db starts here*******/
/********abc.com.zone.db ends here*********/

$ORIGIN abc.com.
$TTL 86400
@       IN      SOA     dns1.abc.com. hostmaster.abc.com. (
2012112901
21600
3600
604800
86400 )
IN      NS      dns1.abc.com.
mx      10      mx.abc.com.

abc     IN      A       1.2.3.4
dns1    IN      A       1.2.3.4
mx      IN      A       1.2.3.4

/********abc.com.zone.rr.db starts here****/

$ORIGIN 3.2.1.IN-ADDR.ARPA.
$TTL 86400
@       IN      SOA     dns1.abc.com. hostmaster.abc.com. (
2012112901
21600
3600
604800
86400 )

@       IN      NS      dns1.abc.com.
1       IN      PTR     abc.abc.com.
2       IN      PTR     abc.abc.com.

/********abc.com.zone.rr.db ends here******/

12. Now restart your server and try resolving your domain names with nslookup. You should see that they resolve to your server!!!

[root@centos#]service named restart
[root@centos#]dig centos.com @192.168.2.124

dig centos.com @192.168.2.124
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.5 <<>> centos.com @192.168.2.124
;; global options: printcmd
;; Got answer:
;; ->>HEADER< ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;centos.com. IN A
;; ANSWER SECTION:
centos.com. 86400 IN A 192.168.2.124
;; AUTHORITY SECTION:
centos.com. 86400 IN NS dns1.centos.com.
;; ADDITIONAL SECTION:
dns1.centos.com. 86400 IN A 192.168.2.124
;; Query time: 2 msec
;; SERVER: 192.168.2.124#53(192.168.2.124)
;; WHEN: Mon Nov 26 12:10:34 2012
;; MSG SIZE rcvd: 79

Leave a Reply