CentOS tutorial on configuring smart DNS with BIND

Source: Internet
Author: User
Tags bind chmod hmac openssl syslog xsl domain name server dnssec

Primary DNS server:

[Root@master/]# Cat/etc/redhat-release
CentOS Release 6.4 (Final)
[Root@master/]# Uname-a
Linux Master 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 00:31:26 UTC 2013 x86_64 x86_64 x86_64
[Root@master/]# Ifconfig | grep "inet Addr"
inet addr:1.1.1.19 bcast:1.1.1.255 mask:255.255.255.0
[Root@master/]# ifconfig eth0:0 192.168.1.19 netmask 255.255.255.0

From a DNS server:


[Root@slave ~]# Cat/etc/redhat-release
CentOS Release 6.7 (Final)
[Root@slave ~]# Uname-a
Linux Slave 2.6.32-573.18.1.el6.x86_64 #1 SMP Tue Feb 9 22:46:17 UTC 2016 x86_64 x86_64 x86_64 gnu/linux
[Root@slave ~]# Ifconfig | grep "inet Addr"
inet addr:1.1.1.20 bcast:1.1.1.255 mask:255.255.255.0
Primary DNS Server compilation:




[Root@master/]# Mkdir/byrd/tools-p


[Root@master/]# Mkdir/byrd/service


[Root@master/]# cd/byrd/tools/


[Root@master tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.28.tar.gz


[Root@master tools]# tar zxf mysql-5.6.28.tar.gz


[Root@master tools]# CD mysql-5.6.28


[Root@master mysql-5.6.28]# CMake. -dcmake_install_prefix=/byrd/service/mysql-5.6.28-dmysql_datadir=/byrd/service/mysql-5.6.28/data-dmysql_unix_ Addr=/byrd/service/mysql-5.6.28/tmp/mysql.sock-dmysql_user=mysql-ddefault_charset=utf8-ddefault_collation=utf8 _general_ci-denabled_local_infile=on-dwith_innobase_storage_engine=1-dwith_federated_storage_engine=1-dwith_ Blackhole_storage_engine=1-dwithout_example_storage_engine=1


[Root@master mysql-5.6.28]# make && make install


[Root@master mysql-5.6.28]# Groupadd MySQL


[Root@master mysql-5.6.28]# useradd-s/sbin/nologin-g mysql MySQL


[Root@master mysql-5.6.28]# ln-s/byrd/service/mysql-5.6.28/usr/local/mysql


[Root@master mysql-5.6.28]#/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql/--datadir=/usr/ local/mysql/data/--user=mysql


[Root@master mysql-5.6.28]# Cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld


[Root@master mysql-5.6.28]# Mv/etc/my.cnf/etc/my.cnf.backup


[Root@master mysql-5.6.28]# cp/usr/local/mysql/support-files/my-default.cnf/etc/my.cnf


[Root@master mysql-5.6.28]#/etc/init.d/mysqld start


[Root@master mysql-5.6.28]# CD ...


[Root@master tools]# wget ftp://ftp.isc.org/isc/bind9/9.9.8/bind-9.9.8.tar.gz


[Root@master tools]# tar zxf bind-9.9.8.tar.gz


[Root@master tools]# CD bind-9.9.8


[Root@master bind-9.9.8]#./configure-h


[Root@master bind-9.9.8]#./configure--prefix=/byrd/service/bind-9.9.8--with-dlz-mysql=/usr/local/mysql-- With-libtool--enable-threads--enable-ipv6--with-dlz-filesystem=yes ' cflags=-o2-g =2-fexceptions-fstack-protector--param=ssp-buffer-size=4-m64-mtune=generic ' cppflags=-DDIG_SIGCHASE '


[Root@master bind-9.9.8]# make && make install


/usr/bin/install-c-M 644./bind.keys/byrd/service/bind-9.9.8/etc


[Root@master bind-9.9.8]# ln-s/byrd/service/bind-9.9.8/usr/local/named


[Root@master bind-9.9.8]# Groupadd-r named-g 25


[Root@master bind-9.9.8]# useradd named-u 25-g named-d/byrd/service/bind-9.9.8/-s/sbin/nologin

Primary DNS server configuration:

[Root@master bind-9.9.8]# Cd/usr/local/named/etc


[Root@master etc]# mkdir/var/named


[Root@master etc]# chown-r named:named/var/named/


[Root@master etc]# chown-r named:named/usr/local/named


[Root@master etc]# chmod 700/usr/local/named/etc/


[Root@master etc]# chown-r named.named/usr/local/named/etc/


[Root@master etc]# cd/var/named/


[Root@master named]#/usr/local/named/bin/dig > Named.root #wget https://www.internic.net/domain/named.root


[Root@master named]# chown-r Root.named/var/named/named.root


[Root@master named]#/usr/local/named/sbin/rndc-confgen >/usr/local/named/etc/rndc.conf #/usr/local/named/sbin/ Rndc-confgen-r/dev/urandom >/usr/local/named/etc/rndc.conf


[Root@master named]# tail/usr/local/named/etc/rndc.conf | Head-9 |sed s/\#//g >/usr/local/named/etc/named.conf


[Root@master named]# CD-


[Root@master etc]# chown-r named.named/usr/local/named/var/


[Root@master etc]# mkdir {/var/named/data,/var/named/zones}-P


[Root@master etc]# chown-r named.named {/var/named/data,/var/named/zones}


[Root@master etc]# grep-v "#"/var/local/named/etc/named.conf


[Root@master zones]# cat/usr/local/named/etc/named.conf


named.conf


Options {


listen-on port {any;};


Directory "/var/named";


Dump-file "/var/named/data/cache_dump.db";


Statistics-file "/var/named/data/named_stats.txt";


Memstatistics-file "/var/named/data/named_mem_stats.txt";


allow-query {any;};


recursion Yes;


Bindkeys-file "/usr/local/named/etc/bind.key";


Allow-transfer {1.1.1.20;};


# forwarders {114.114.114.114;};


};


Logging {


Channel Default_debug {


File "Data/named.run";


Severity dynamic;


};


Channel Gsquery {


File "Data/query.log" versions 3 size 20m;


Severity info;


Print-time Yes;


Print-category Yes;


Print-severity Yes;


};


Category queries {gsquery;};


};


Key "Rndc-key" {


Algorithm HMAC-MD5;


Secret "ovh1p5jg000glbwjyifxrq==";


};





Controls {


inet 127.0.0.1 Port 953


Allow {127.0.0.1} keys {"Rndc-key";};


};


Include "/var/named/named.rfc1912.zones";


[Root@master zones]# Cat/var/named/named.rfc1912.zones


Zone "localhost" in {


Type master;


File "Zones/named.localhost";


allow-update {none;};


};


Zone "1.0.0.127.in-addr.arpa" in {


Type master;


File "Zones/named.loopback";


allow-update {none;};


};


Zone "111cn.net" in {


Type master;


File "zones/111cn.net. Zone";


allow-update {none;};


Allow-transfer {1.1.1.20;};


Notify yes;


Also-notify {1.1.1.20;}; #允许slave主机以外的备份


};


Zone "1.168.192.in-addr.arpa" {


Type master;


File "Zones/192.168.1.zone";


allow-update {none;};


Notify yes;


Allow-transfer {1.1.1.20;};


};


[Root@master zones]# cat/var/named/zones/111cn.net. Zone


$TTL 600


@ in SOA ns1.111cn.net. Admin.111cn.net. (


2015050702; Serial


1D; Refresh


1H; Retry


1W; Expire


3H); Minimum


In NS ns1


In NS ns2.111cn.net.


In A 1.1.1.19


NS1 in A 1.1.1.19


NS2 in A 1.1.1.20


www in A 192.168.1.19


BBS in A 192.168.1.92


Qwer in A 1.2.3.4


Test in CNAME www


Blog in CNAME www


[Root@master zones]# Cat/var/named/zones/192.168.1.zone


$TTL 1D


@ in SOA ns1.111cn.net. Admin.111cn.net. (


2015050701; Serial


10; Refresh


1H; Retry


1W; Expire


3H); Minimum


@ in NS ns1.111cn.net.


@ in NS ns2.111cn.net.


PTR localhost.


In PTR ns1.111cn.net.


In PTR ns2.111cn.net.


In PTR www.111cn.net.


In PTR ww.111cn.net.


[Root@master zones]# Cat Named.localhost


$TTL 1D


@ in SOA @ rname.invalid. (


0; Serial


1D; Refresh


1H; Retry


1W; Expire


3H); Minimum


NS @


A 127.0.0.1


AAAA:: 1


PTR localhost.


[Root@master zones]# Cat Named.loopback


$TTL 1D


@ in SOA @ rname.invalid. (


0; Serial


1D; Refresh


1H; Retry


1W; Expire


3H); Minimum


NS @


A 127.0.0.1


AAAA:: 1


PTR localhost.

[Root@master zones]#/usr/local/named/sbin/named-c/usr/local/named/etc/named.conf-4u named

Positive solution, inverse solution test:

[Root@master zones]#/usr/local/named/bin/dig www.111cn.net





;; Question section:


; www.111cn.net. In A


;; ANSWER section:


Www.111cn.net. 192.168.1.19 in A


;; Authority section:


111cn.net. In NS ns1.111cn.net.


;; ADDITIONAL section:


Ns1.111cn.net. 1.1.1.19 in A





[Root@master zones]#/usr/local/named/bin/dig blog.111cn.net





;; Question section:


; blog.111cn.net. In A


;; ANSWER section:


Blog.111cn.net. Www.111cn.net in CNAME.


Www.111cn.net. 192.168.1.19 in A





[Root@master zones]#/usr/local/named/bin/dig-x 192.168.1.19





;; Question section:


; 19.1.168.192.in-addr.arpa. In PTR


;; ANSWER section:


19.1.168.192.in-addr.arpa. 86400 in PTR www.111cn.net.


19.1.168.192.in-addr.arpa. 86400 in PTR ns1.111cn.net.


;; Authority section:


1.168.192.in-addr.arpa. 86400 in NS ns1.111cn.net.


;; ADDITIONAL section:


Ns1.111cn.net. 1.1.1.19 in A





[Root@master zones]#/usr/local/named/bin/dig-x 192.168.1.92





;; Question section:


; 92.1.168.192.in-addr.arpa. In PTR


;; ANSWER section:


92.1.168.192.in-addr.arpa. 86400 in PTR bbs.111cn.net.


;; Authority section:


1.168.192.in-addr.arpa. 86400 in NS ns1.111cn.net.

Compiling from a DNS server:




[Root@slave bind-9.9.8]# yum install vim get OpenSSL openssl-devel lrzsz dos2unix gcc gcc-c++-y


[Root@slave ~]# Mkdir/byrd/tools-p


[Root@slave ~]# Mkdir/byrd/service


[Root@slave ~]# cd/byrd/tools/


[Root@slave tools]# wget ftp://ftp.isc.org/isc/bind9/9.9.8/bind-9.9.8.tar.gz


[Root@slave tools]# tar zxf bind-9.9.8.tar.gz


[Root@slave tools]# CD bind-9.9.8


[Root@slave bind-9.9.8]#./configure--prefix=/byrd/service/bind-9.9.8--with-libtool--enable-threads--enable-ipv6 ' Cflags=-o2-g-pipe-wall-wp,-d_fortify_source=2-fexceptions-fstack-protector--param=ssp-buffer-size=4-m64-mtune =generic ' cppflags=-ddig_sigchase '


[Root@slave bind-9.9.8]# make && make install


[Root@slave bind-9.9.8]#/usr/local/named/sbin/rndc-confgen-r/dev/urandom >/usr/local/named/etc/rndc.conf


[Root@slave etc]# tail/usr/local/named/etc/rndc.conf | Head-9 |sed s/\#//g >/usr/local/named/etc/named.conf


[Root@slave etc]# mkdir {/var/named/data,/var/named/slaves/}-P


[Root@slave etc]# chown-r named.named {/var/named/data,/var/named/slaves/}


To configure from a DNS server:

[Root@slave named]# cat/usr/local/named/etc/named.conf


Options {


listen-on port {any;};


Directory "/var/named";


Dump-file "/var/named/data/cache_dump.db";


Statistics-file "/var/named/data/named_stats.txt";


Memstatistics-file "/var/named/data/named_mem_stats.txt";


allow-query {any;};


recursion Yes;


Bindkeys-file "/usr/local/named/etc/bind.key";


};


Logging {


Channel Default_debug {


File "Data/named.run";


Severity dynamic;


};


Channel Gsquery {


File "Data/query.log" versions 3 size 20m;


Severity info;


Print-time Yes;


Print-category Yes;


Print-severity Yes;


};


Category queries {gsquery;};


};


Key "Rndc-key" {


Algorithm HMAC-MD5;


Secret "izmcwxjeanm1nksq+1qqxa==";


};





Controls {


inet 127.0.0.1 Port 953


Allow {127.0.0.1} keys {"Rndc-key";};


};





Include "/var/named/named.rfc1912.zones";


[Root@slave named]# Cat/var/named/named.rfc1912.zones


Zone "111cn.net" in {


Type slave;


File "slaves/111cn.net. Zone";


Masters {1.1.1.19;};


Allow-transfer {none;};


};





Zone "1.168.192.in-addr.arpa" {


Type slave;


File "Slaves/192.168.1.zone";


Masters {1.1.1.19;};


Allow-transfer {none;};


};

To verify synchronization from the server:




[Root@master zones]# cat 111cn.net. Zone


$TTL 60


@ in SOA ns1.111cn.net. Admin.111cn.net. (


2015050703; Serial


In NS ns1


In NS ns2.111cn.net.


In A 1.1.1.19


NS1 in A 1.1.1.19


Test in CNAME www








21:43:21 MASTER named[38968]: Client 1.1.1.20#35403 (111cn.net): Transfer of ' 111cn.net/in ': Axfr-style IXFR started


21:43:21 MASTER named[38968]: Client 1.1.1.20#35403 (111cn.net): Transfer of ' 111cn.net/in ': Axfr-style IXFR Ended


21:43:21 MASTER named[38968]: Client 1.1.1.20#58007:received notify for zone ' 111cn.net '





[Root@slave named]#/usr/local/named/sbin/named-compilezone-f raw-f text-o/tmp/111cn.net. txt 111CN.NET/VAR/NAMED/SL Aves/111cn.net. Zone


Zone 111cn.net/in:loaded Serial 2015050703


[Root@slave named]# cat/tmp/111cn.net. txt


111cn.net. Ns1.111cn.net in SOA. Admin.111cn.net. 2015050703 86400 3600 604800 10800


111cn.net. In NS ns1.111cn.net.


111cn.net. In NS ns2.111cn.net.


111cn.net. 1.1.1.19 in A


Bbs.111cn.net. 192.168.1.92 in A


Blog.111cn.net. Www.111cn.net in CNAME.


Ns1.111cn.net. 1.1.1.19 in A


Ns2.111cn.net. 1.1.1.20 in A


Qwer.111cn.net. 1.2.3.4 in A


Test.111cn.net. Www.111cn.net in CNAME.


Www.111cn.net. 192.168.1.19 in A








21:43:21 Slave named[25033]: Transfer of ' 111cn.net/in ' from 1.1.1.19#53:connected using 1.1.1.20#35403


21:43:21 Slave named[25033]: Zone 111cn.net/in:transferred serial 2015050703


21:43:21 Slave named[25033]: Transfer of ' 111cn.net/in ' from 1.1.1.19#53:transfer status:success


21:43:21 Slave named[25033]: Transfer of ' 111cn.net/in ' from 1.1.1.19#53:transfer completed:1-messages, records, 298 bytes, 0.002 secs (149000 bytes/sec)


21:43:21 Slave named[25033]: Zone 111cn.net/in:sending notifies (serial 2015050703)





[Root@master zones]# tail-3 111cn.net. Zone


Q in A 11.11.111.11


A.Q in A 22.22.22.22


B.Q in A 33.33.33.33


[Root@master zones]# head-3/var/named/zones/111cn.net. Zone


2015050704; Serial


[Root@master zones]#/usr/local/named/sbin/rndc Reload





[Root@slave etc]#/usr/local/named/sbin/named-compilezone-f raw-f text-o/tmp/111cn.net. txt 111cn.net/var/named/slav Es/111cn.net. Zone


Zone 111cn.net/in:loaded Serial 2015050704


Dump Zone to/tmp/111cn.net. Txt...done


Ok


[Root@slave etc]# cat/tmp/111cn.net. txt


111cn.net. In SOA ns1.111cn.net. 111cn.net. Admin.111cn.net. 2015050704 86400 3600 604800 10800


111cn.net. In NS ns1.111cn.net.


111cn.net. In NS ns2.111cn.net.


111cn.net. 1.1.1.19 in A


Bbs.111cn.net. 192.168.1.92 in A


Blog.111cn.net. Www.111cn.net in CNAME.


Ns1.111cn.net. 1.1.1.19 in A


Ns2.111cn.net. 1.1.1.20 in A


Q.111cn.net. 11.11.111.11 in A


A.q.111cn.net. 22.22.22.22 in A


B.q.111cn.net. 33.33.33.33 in A


Qwer.111cn.net. 1.2.3.4 in A


Test.111cn.net. Www.111cn.net in CNAME.


Www.111cn.net. 192.168.1.19 in A


Yum Version compilation parameters:

0


--build=x86_64-redhat-linux-gnu--host=x86_64-redhat-linux-gnu--target=x86_64-redhat-linux-gnu--program-prefix= --PREFIX=/USR--exec-prefix=/usr--bindir=/usr/bin--sbindir=/usr/sbin--sysconfdir=/etc--datadir=/usr/share-- Includedir=/usr/include--libdir=/usr/lib64--libexecdir=/usr/libexec--sharedstatedir=/var/lib--mandir=/usr/ Share/man--infodir=/usr/share/info--with-libtool--localstatedir=/var--enable-threads--enable-ipv6-- ENABLE-FILTER-AAAA--with-pic--disable-static--disable-openssl-version-check--enable-rpz-nsip-- Enable-rpz-nsdname--with-dlopen=yes--with-dlz-ldap=yes--with-dlz-postgres=yes--with-dlz-mysql=yes-- With-dlz-filesystem=yes--with-gssapi=yes--disable-isc-spnego--with-docbook-xsl=/usr/share/sgml/docbook/ Xsl-stylesheets--enable-fixed-rrset Build_alias=x86_64-redhat-linux-gnu Host_alias=x86_64-redhat-linux-gnu Target _alias=x86_64-redhat-linux-gnu ' cflags=-o2-g-pipe-wall-wp,-d_fortify_source=2-fexceptions-fstack-protector-- Param=ssp-buffer-siZe=4-m64-mtune=generic ' cppflags=-ddig_sigchase '

Startup script: {Using the Yum version of the script, slightly modified}

Shell




[Root@master init.d]# Cat named


#!/bin/bash


#


# named this shell script takes care of starting and stopping


# named (BIND DNS Server).


#


# Chkconfig:-13 87


# description:named (BIND) is a Domain Name Server (DNS) \


# This is used to resolve host names to IP addresses.


# Probe:true





### BEGIN INIT INFO


# provides: $named


# Required-start: $local _fs $network $syslog


# required-stop: $local _fs $network $syslog


# Default-start:


# default-stop:0 1 2 3 4 5 6


# short-description:start|stop|status|restart|try-restart|reload|force-reload DNS Server


# Description:control ISC BIND implementation of DNS server


### End INIT INFO





# Source function library.


. /etc/rc.d/init.d/functions





[-r/etc/sysconfig/named] &&. /etc/sysconfig/named





Retval=0


Export Krb5_ktname=${keytab_file:-/etc/named.keytab}





Named= ' named '


#if [-X/USR/SBIN/NAMED-SDB]; Then


# named= ' Named-sdb '


#fi





# Don ' t kill named during clean-up


NAMED_SHUTDOWN_TIMEOUT=${NAMED_SHUTDOWN_TIMEOUT:-25}





If [-N "$ROOTDIR"]; Then


Rootdir= ' echo $ROOTDIR | Sed ' s#//*#/#g; s#/$## ';


Rdl= '/usr/bin/readlink $ROOTDIR ';


If [-N "$rdl"]; Then


Rootdir= "$RDL";


Fi


Fi





Pidfile= "/usr/local/named/var/run/named/named.pid"





Rootdir_mount= '/etc/named/etc/pki/dnssec-keys/var/named/etc/named.conf


/etc/named.dnssec.keys/etc/named.rfc1912.zones/etc/rndc.conf/etc/rndc.key


/usr/lib64/bind/usr/lib/bind/etc/named.iscdlv.key/etc/named.root.key '


Umount_chroot_conf ()


{


If [-N "$ROOTDIR"]; Then


For all in $ROOTDIR _mount; Todo


# Check If file is Mount Target. Do not use/proc/mounts because detecting


# of modified mounted files can fail.


If Mount | Grep-q '. * on ' "$ROOTDIR $all" '. * '; Then


Umount "$ROOTDIR $all"


# Remove Temporary created files


[-F "$all"] && rm-f "$ROOTDIR $all"


Fi


Done


Fi


}





Check_pidfile () {


Pid= "' Pidofproc-p" $ROOTDIR $pidfile "" $named "" "


If [-N "$PID"] && ["Ps-p" $PID "--no-headers-o comm" "!=" $named "]; Then


Rm-f $ROOTDIR $pidfile &>/dev/null


Fi


}





Pidofnamed () {


Pidofproc-p "$ROOTDIR $pidfile" "$named";


}





# Check If all what named needs running


Start ()


{


["$EUID"!= "0"] && Exit 4





# Source Networking configuration.


[-r/etc/sysconfig/network] &&. /etc/sysconfig/network





# Check that networking are up


# ["${networking}" = "no"] && exit 1








# [-x/usr/sbin/' $named] | | Exit 5





if [!-s/usr/local/named/etc/rndc.key-a!-s/usr/local/named/etc/rndc.conf]; Then


# Generate Rndc.key If doesn ' t exist and there is no rndc.conf


Echo-n $ "Generating/usr/local/named/etc/rndc.key:"


If/usr/local/named/sbin/rndc-confgen-a-r/dev/urandom >/dev/null 2>&1; Then


chmod 640/usr/local/named/etc/rndc.key


Chown Root.named/usr/local/named/etc/rndc.key


[-x/sbin/restorecon] &&/sbin/restorecon/usr/local/named/etc/rndc.key


Success $ "/usr/local/named/etc/rndc.key generation"


Echo


Else


Failure $ "/usr/local/named/etc/rndc.key generation"


Echo


Fi


Fi





# handle-c option


previous_option= ' unspecified ';


For a in $OPTIONS; Todo


if [$previous _option = '-C ']; Then


Named_conf= $a;


Fi


Previous_option= $a;


Done





NAMED_CONF=${NAMED_CONF:-/USR/LOCAL/NAMED/ETC/NAMED.CONF};





# Check if named is running before mounting files/dirs


Echo-n $ "Starting named:"


Check_pidfile


If [-N "' pidofnamed '"]; Then


Echo-n $ "Named:already Running"


Success


Echo


Exit 0;


Fi





If [-N "${rootdir}"-A "X${rootdir}"!= "x/"]; Then


Options= "${options}-t ${rootdir}"


ckcf_options= "$CKCF _options-t ${rootdir}";


[-s/etc/localtime] && cp-fp/etc/localtime ${rootdir}/etc/localtime;


Fi





Retval=0


# Check if configuration is correct


If [-x/usr/local/named/sbin/named-checkconf] && [-x/usr/local/named/sbin/named-checkzone] &&/usr/l ocal/named/sbin/named-checkconf $ckcf _options ${named_conf} >/dev/null 2>&1; Then





Daemon--pidfile "$ROOTDIR $pidfile"/usr/local/named/sbin/"$named" -4u named ${options};


Retval=$?


If [$RETVAL-eq 0]; Then


Rm-f/var/run/{named,named-sdb}.pid;


Ln-s "$ROOTDIR $pidfile"/var/run/"$named". PID;


Fi





Else


Named_err= "'/usr/local/named/sbin/named-checkconf $ckcf _options $named _conf 2>&1 '";


Echo


echo "Error in Named configuration:";


echo "$named _err";


Failure


Echo


[-x/usr/bin/logger] && echo "$named _err" | /usr/bin/logger-pdaemon.error-tnamed;


Umount_chroot_conf


Exit 2;


Fi


Echo


If [$RETVAL-eq 0]; Then


touch/var/lock/subsys/named;


Else


Umount_chroot_conf


Exit 7;


Fi


return 0;


}





Stop () {


["$EUID"!= "0"] && Exit 4





# Stop Daemons.


Echo-n $ "Stopping named:"


Check_pidfile


[-X/USR/SBIN/RNDC] &&/usr/sbin/rndc stop >/dev/null 2>&1;


Retval=$?


# was RNDC successful?


["$RETVAL"-eq 0] | | \


Killproc-p "$ROOTDIR $pidfile" "$named"-term >/dev/null 2>&1





Timeout=0


Retval=0


While Pidofnamed &>/dev/null; Todo


If [$timeout-ge $NAMED _shutdown_timeout]; Then


Retval=1


Break


Else


Sleep 2 && echo-n "."


timeout=$ ((timeout+2))


Fi


Done





Umount_chroot_conf





# Remove PID Files


If [$RETVAL-eq 0]; Then


Rm-f/var/lock/subsys/named


Rm-f/var/run/{named,named-sdb}.pid


Fi





If [$RETVAL-eq 0]; Then


Success


Else


Failure


Retval=1


Fi


Echo


Return $RETVAL


}








Rhstatus () {


[-X/USR/SBIN/RNDC] &&/USR/SBIN/RNDC status;


Check_pidfile


Status-p "$ROOTDIR $pidfile"-L named/usr/sbin/"$named";


Return $?


}





Restart () {


Stop


Start


}





Reload () {


["$EUID"!= "0"] && exit





Echo-n $ "Reloading" $named ":"


Check_pidfile


p= ' pidofnamed '


Retval=$?


If ["$RETVAL"-eq 0]; Then


/USR/SBIN/RNDC Reload >/dev/null 2>&1 | | /bin/kill-hup $p;


Retval=$?


Fi


["$RETVAL"-eq 0] && success $ "$named Reload" | | Failure $ "$named Reload"


Echo


Return $RETVAL


}





Checkconfig () {


ckcf_options= '-Z ';


If [-N "${rootdir}"-A "X${rootdir}"!= "x/"]; Then


ckcf_options= "$CKCF _options-t ${rootdir}";


if! [-E "$ROOTDIR/$PIDFILE"]; Then


Mount_chroot_conf


Fi


Fi


If [-x/usr/sbin/named-checkconf] && [-x/usr/sbin/named-checkzone] &&/usr/sbin/named-checkconf $CKCF _options ${named_conf}; Then


Retval=0


Else


Retval=1


Fi


if! [-E "$ROOTDIR/$PIDFILE"]; Then


Umount_chroot_conf


Fi


Return $RETVAL


}





# How we were called.


Case "$" in


Start


Start


;;


Stop


Stop


;;


Status


Rhstatus;


Retval=$?


;;


Restart)


Restart


;;


Condrestart|try-restart)


if [-e/var/lock/subsys/named]; then restart; Fi


;;


Reload


Reload


;;


Force-reload)


if! Reload then restart; Fi


;;


Checkconfig|configtest|check|test)


Checkconfig


Retval=$?


;;


*)


echo $ "Usage: $ {start|stop|status|restart|try-restart|reload|force-reload}"


["X$1" = "x"] && exit 0


Exit 2


Esac


Exit $RETVAL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.