Configuring DNS server in linux (RHEL)
- one for a simple caching name server only client
- one for a slave secondary server
- one for a master name server primary server.
- Caching Only DNS
- Master DNS
- Slave DNS
- Commands are Unix-compatible.
- The source path is /var/tmp. other paths are possible.
- Installations were tested on Red Hat Linux 6.1 and 6.2.
- All steps in the installation will happen in super-user account root.
- ISC BIND version number is 8.2.2-patchlevel5
ISC BIND Homepage:http://www.isc.org/
|
ISC BIND FTP Site: 204.152.184.27
|
[root@deep] /# mkdir /var/tmp/bind
[root@deep] /# cp bind-contrib.tar.gz /var/tmp/bind/
[root@deep] /# cp bind-doc.tar.gz /var/tmp/bind/
[root@deep] /# cp bind-src.tar.gz /var/tmp/bind/
|
[root@deep ]/bind# tar xzpf bind-contrib.tar.gz
[root@deep ]/bind# tar xzpf bind-doc.tar.gz
[root@deep ]/bind# tar xzpf bind-src.tar.gz
|
total 24
drwxr-xr-x 2 harrypotter harrypotter 4096 Jun 8 13:00 Caching-Only-DNS/
-rw-r--r-- 1 harrypotter harrypotter 484 Jun 8 13:00 Compile-BIND
drwxr-xr-x 2 harrypotter harrypotter 4096 Jun 8 13:00 Primary-Master-DNS/
drwxr-xr-x 2 harrypotter harrypotter 4096 Jun 8 13:00 Secondary-Slave-DNS/
-rwx------ 1 harrypotter harrypotter 300 Jun 8 13:00 bind.sh*
drwxr-xr-x 3 harrypotter harrypotter 4096 Jun 8 13:00 init.d/
|
- Copy the named.conf file to the /etc/ directory.
- Copy the db.127.0.0 file to the /var/named/ directory.
- Copy the db.cache file to the /var/named/ directory.
- Copy the named script file to the /etc/rc.d/init.d/ directory.
- Copy the named.conf file to the /etc/ directory.
- Copy the db.127.0.0 file to the /var/named/ directory.
- Copy the db.cache file to the /var/named/ directory.
- Copy the db.208.164.186 file to the /var/named/ directory.
- Copy the db.openna file to the /var/named/ directory.
- Copy the named script file to the /etc/rc.d/init.d/ directory.
- Copy the named.conf file to the /etc/ directory.
- Copy the db.127.0.0 file to the /var/named/ directory.
- Copy the db.cache file to the /var/named/ directory.
- Copy the named script file to the /etc/rc.d/init.d/ directory.
- named.conf
- db.127.0.0
- db.cache
- named script
options {
directory "/var/named";
forwarders { 208.164.186.1; 208.164.186.2; };
forward only;
};
//
// a caching only nameserver config
zone "." in {
type hint;
file "db.cache";
};
zone "0.0.127.in-addr.arpa" in {
type master;
file "db.127.0.0";
};
|
$TTL 345600
@ IN SOA localhost. root.localhost. (
00 ; Serial
86400 ; Refresh
7200 ; Retry
2592000 ; Expire
345600 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
|
[root@deep]# dig @.aroot-servers.net . ns > db.cache
|
- named.conf
- db.127.0.0
- db.208.164.186
- db.openna
- db.cache
- named script
options {
directory "/var/named";
fetch-glue no;
recursion no;
transfer-format many-answers;
};
// These files are not specific to any zone
zone "." in {
type hint;
file "db.cache";
};
zone "0.0.127.in-addr.arpa" in {
type master;
file "db.127.0.0";
};
// These are our primary zone files
zone "openna.com" in {
type master;
file "db.openna ";
};
zone "186.164.208.in-addr.arpa" in {
type master;
file "db.208.164.186";
};
|
; Revision History: April 22, 1999 - admin@mail.openna.com
; Start of Authority (SOA) records.
$TTL 345600
@ IN SOA deep.openna.com. admin.mail.openna.com. (
00 ; Serial
86400 ; Refresh
7200 ; Retry
2592000 ; Expire
345600 ) ; Minimum
; Name Server (NS) records.
NS deep.openna.com.
NS mail.openna.com.
; only One PTR record.
1 PTR localhost.
|
; Revision History: April 22, 1999 - admin@mail.openna.com
; Start of Authority (SOA) records.
$TTL 345600
@ IN SOA deep.openna.com. admin.mail.openna.com. (
00 ; Serial
86400 ; Refresh
7200 ; Retry
2592000 ; Expire
345600 ) ; Minimum
; Name Server (NS) records.
NS deep.openna.com.
NS mail.openna.com.
; Addresses Point to Canonical Names (PTR) for Reverse lookups
1 PTR deep.openna.com.
2 PTR mail.openna.com.
3 PTR www.openna.com.
|
; Revision History: April 22, 1999 - admin@mail.openna.com
; Start of Authority (SOA) records.
$TTL 345600
@ IN SOA deep.openna.com. admin.mail.openna.com. (
00 ; Serial
86400 ; Refresh
7200 ; Retry
2592000 ; Expire
345600 ) ; Minimum
; Name Server (NS) records.
NS deep.openna.com.
NS mail.openna.com.
; Mail Exchange (MX) records.
MX 0 mail.openna.com.
; Address (A) records.
localhost A 127.0.0.1
deep A 208.164.186.1
mail A 208.164.186.2
www A 208.164.186.3
; Aliases in Canonical Name (CNAME) records.
;www CNAME deep.openna.com.
|
[root@deep] /# dig @.aroot-servers.net . ns > db.cache
|
21.5. Secondary slave name Server
The purpose of a slave name server is to share the load with the masterserver, or handle the entire load if the masterserver is down. A slave name server loads its data over the network from another name server usually the master name server, but it can load from another slavename server too. This process is called a zonetransfer. Necessary files to setup a secondary slave name server are:
To configure the /etc/named.conffile for a slave name server, use this configuration for the server on your network that acts as a slave name server. You must modify the named.conf file on the slavename server host. Change every occurrence of primary to secondary except for 0.0.127.in-addr.arpa and add a masters line with the IP address of the master server as shown below.
Create the named.conf file (touch /etc/named.conf) and add:
options {
directory "/var/named";
fetch-glue no;
recursion no;
allow-query { 208.164.186/24; 127.0.0/8; };
allow-transfer { 208.164.186.1; };
transfer-format many-answers;
};
// These files are not specific to any zone
zone "." in {
type hint;
file "db.cache";
};
zone "0.0.127.in-addr.arpa" in {
type master;
file "db.127.0.0";
};
// These are our slave zone files
zone "openna.com" in {
type slave;
file "db.openna";
masters { 208.164.186.1; };
};
zone "186.164.208.in-addr.arpa" in {
type slave;
file "db.208.164.186";
masters { 208.164.186.1; };
};
|
This tells the name server that it is a slave for the zone openna.com and should track the version of this zone that is being kept on the host 208.164.186.1.
A slave name server doesn't need to retrieve all of its database (db) files over the network because these db files db.127.0.0 and db.cache are the same as on a primary master, so you can keep a local copy of these files on the slave name server.
21.5.1. /etc/rc.d/init.d/named script
Configure your /etc/rc.d/init.d/namedscript file to start and stop the BIND/DNS daemon on your Server. This configuration script file can by used for all type of name server caching, master or slave.
Create the named script file touch /etc/rc.d/init.d/namedand add:
#!/bin/sh
#
# named This shell script takes care of starting and stopping # named (BIND DNS server). #
# chkconfig: - 55 45
# description: named (BIND) is a Domain Name Server (DNS) \ # that is used to resolve host names to IP addresses. # probe: true
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/named ] || exit 0 [ -f /etc/named.conf ] || exit 0
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting named: "
daemon named
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named
echo
;;
stop)
# Stop daemons.
echo -n "Shutting down named: "
killproc named
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named
echo
;;
status)
/usr/sbin/ndc status
exit $?
;;
restart)
$0 stop
$0 start
;;
reload)
/usr/sbin/ndc reload
exit $?
;;
probe)
# named knows how to reload intelligently; we don't want linuxconf
# to offer to restart every time
/usr/sbin/ndc reload >/dev/null 2>&1 || echo start
exit 0
;;
*)
echo "Usage: named {start|stop|status|restart}"
exit 1
esac
exit $RETVAL
|
Now, make this script executable and change its default permissions:
[root@deep]# chmod 700 /etc/rc.d/init.d/named
|
Create the symbolic rc.dlinks for BIND/DNS with the command:
[root@deep]# chkconfig --add named
|
The BIND/DNS script will not automatically start the named daemon when you reboot the server. You can change its default by executing the following command:
[root@deep]# chkconfig --level 345 named on
|
Start your DNS Server manually with the following command:
[root@deep]# /etc/rc.d/init.d/named start
|
Starting named: [ OK ]
|
This part focuses on preventing ISC BIND/DNS from being used as a point of break-in to the system hosting it. Since ISC BIND/DNS performs a relatively large and complex function, the potential for bugs that affect security is rather high with this software. In fact, there have been exploitable bugs in the past that allowed a remote attacker to obtain root access to hosts running ISC BIND/DNS. To minimize this risk, ISC BIND/DNS can be run as a non-root user, which will limit any damage to what can be done as a normal user with a local shell. Of course, this is not enough for the security requirements of most DNS servers, so an additional step can be taken - that is, running ISC BIND in a chroot jail.
|
- To find the shared library dependencies of named, execute the following command:
[root@deep] /# ldd /usr/sbin/named
libc.so.6 => /lib/libc.so.6 (0x40017000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
|
- Make a note of the files listed above; you will need these later in our steps.
[root@deep] /# /etc/rc.d/init.d/named stop
|
- Require only if an existing named daemon is running.
Shutting down named: [ OK ]
|
[root@deep] /# mkdir -p /chroot/named
|
- Next, create the rest of directories as follows:
[root@deep] /# mkdir /chroot/named/dev
[root@deep] /# mkdir /chroot/named/lib
[root@deep] /# mkdir /chroot/named/etc
[root@deep] /# mkdir -p /chroot/named/usr/sbin
[root@deep] /# mkdir -p /chroot/named/var/run
[root@deep] /# mkdir /chroot/named/var/named
|
- Now copy the main configuration file, the zone files, the named and the named-xfer programs into the appropriate places in the chroot jail directory:
[root@deep] /# cp /etc/named.conf /chroot/named/etc/
[root@deep] /# cd /var/named ; cp -a . /chroot/named/var/named/
[root@deep] /# mknod /chroot/named/dev/null c 1 3
[root@deep] /# chmod 666 /chroot/named/dev/null
[root@deep] /# cp /usr/sbin/named /chroot/named/usr/sbin/
[root@deep] /# cp /usr/sbin/named-xfer /chroot/named/usr/sbin/
|
- To make the named directory and all its files own by the named process name under the slave server, use the command:
[root@deep] /# chown -R named.named /chroot/named/var/named/
|
[root@deep] /# cp /lib/libc.so.6 /chroot/named/lib/
[root@deep] /# cp /lib/ld-linux.so.2 /chroot/named/lib/
|
[root@deep] /# cp /etc/localtime /chroot/named/etc/
[root@deep] /# cp /etc/nsswitch.conf /chroot/named/etc/
|
- Set the immutable bit on nsswitch.conf file:
[root@deep] /# cd /chroot/named/etc/
[root@deep etc]# chattr +i nsswitch.conf
|
- Set the immutable bit on named.conf file:
[root@deep] /# cd /chroot/named/etc/
[root@deep etc]# chattr +i named.conf
|
- A file with the +i attribute cannot be modified, deleted or renamed; no link can be created to this file and no data can be written to it. Only the superuser can set or clear this attribute.
[root@deep] /#useradd -c DNS Server -u 53 -s /bin/false -r -d /chroot/named named 2>/dev/null || :
|