源碼安裝bind9.16.13


源碼安裝Bind-9.16.13

環境准備

 

1、  使用yum完成以下軟件安裝。

yum -y install net-tools

yum -y install gcc*

yum -y install tcpdump

yum -y install cmake

yum -y install bind-utils

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

yum -y install libffi-devel -y

yum -y install libxml*

yum -y install git

yum -y install libtool

yum -y install wget

yum -y install vim

yum -y install python-pip

yum -y install libcap-devel

 

2、  在https://www.isc.org/download/ 下載最新stable版本bind

[root@dnscache ~]# wget https://downloads.isc.org/isc/bind9/9.16.13/bind-9.16.13.tar.xz

 

3、  執行以下命令安裝libuv

yum install -y epel-release

yum install -y libuv

yum install -y libuv-devel

4、安裝ply,如果不安裝ply模塊,bind在編譯時會報錯

    #pip install ply

 

5、  創建named用戶及相關目錄。

使用53端口作為named組和named用戶的ID號

groupadd -g 53 -r named

useradd -u 53 -s /sbin/nolgin -r named -g named

 

 

安裝bind

1、  解壓下載的新版本bind

[root@dnscache ~]# tar -xvf bind-9.16.13.tar.xz

 

2、  編譯,安裝bind

[root@dnscache ~]# cd bind-9.16.13

[root@dnscache bind-9.16.13]# ./configure --prefix=/usr/local/bind

[root@dnscache bind-9.16.13]# make && make install

 

3、  安裝成功后 /usr/local/bind目錄中的內容如下

 

 

 

bind初始化配置

1、# cd /usr/local/bind/

 

2、[root@dnscache bind]# sbin/rndc-confgen > etc/rndc.conf

 

   注意:如果這里卡住不動可改用下面的命令

sbin/rndc-confgen -r /dev/urandom > etc/rndc.conf

 

3、[root@dnscache bind]# cd /usr/local/bind/etc/

 

4、[root@dnscache etc]# tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf

 

   此時named.conf文件內容如下:

 

 

 

4、  編輯配置文件,在當前文件添加以下內容

# vim /usr/local/bind/etc/named.conf

 

  • options {

    listen-on port 53 {127.0.0.1; };

    listen-on-v6 port 53 {::1;};

    directory "/usr/local/bind/var/run";

    pid-file "named.pid";

    recursion yes;

    querylog yes;

    allow-query { any; };

 

};

 

logging {

        channel query_log {

                file "data/bind_query.log" versions 3;

                severity dynamic;

                print-category yes;

                print-time yes;

                print-severity yes;

        };

        category queries { query_log; };

};

 

zone "." IN{

         type hint;

         file "named.ca";

   };

 

 

 

include "/usr/local/bind/etc/named.rfc1912.zones";

 

5、  在/usr/local/bind/var/run目錄下創建一個data目錄用來存放日志文件

# cd /usr/local/bind/var/run/

# mkdir data

 

6、  在/usr/local/bind/var/run目錄下生成named.ca數據文件

# cd /usr/local/bind/var/run/

# dig -t NS . >/usr/local/bind/var/run/named.ca

 

7、  在/usr/local/bind/etc/目錄下創建named.rfc1912.zones文件,並添加以下內容

# vim /usr/local/bind/etc/named.rfc1912.zones

zone "localhost.localdomain" IN {

        type master;

        file "named.localhost";

        allow-update { none; };

};

 

zone "localhost" IN {

        type master;

        file "named.localhost";

        allow-update { none; };

};

 

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {

        type master;

        file "named.loopback";

        allow-update { none; };

};

 

zone "1.0.0.127.in-addr.arpa" IN {

        type master;

        file "named.loopback";

        allow-update { none; };

};

 

zone "0.in-addr.arpa" IN {

        type master;

        file "named.empty";

        allow-update { none; };

};

8、  在/usr/local/bind/var/run目錄下創建對應數據文件

由named.rfc1912.zones文件可知有named.localhost、named.loopback、named.empty數據文件

# cd /usr/local/bind/var/run/

# vim 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

 

# vim 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.

 

# vim named.empty

$TTL 3H

@       IN SOA  @ rname.invalid. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

        NS      @

        A       127.0.0.1

        AAAA    ::1

 

9、# chown -R named:named /usr/local/bind

 

10、檢查named.conf文件

   # cd /usr/local/bind/sbin/

   # ./named-checkconf ../etc/named.conf

 

運行bind

1、  執行如下命令啟動bind

# /usr/local/bind/sbin/named -u named -c /usr/local/bind/etc/named.conf

 

2、  測試能正常解析

# ps -ef|grep named

# netstat -anp|grep 53

# dig @127.0.0.1 www.baidu.com

 

 

 

 

設置bind開機啟動服務

1、  在/etc/rc.d/init.d/目錄下編寫一個名為named的shell腳本

# cd /etc/rc.d/init.d/

# vim named

#!/bin/bash

#chkconfig: 545 35 75

#description: named DNS service manager

 

data=" /usr/local/bind/sbin/named -u named -c /usr/local/bind/etc/named.conf"

function START(){

        eval $data && echo -e "BIND9 start\033[32m ok\033[0m"

}

function STOP(){

        kill `cat /usr/local/bind/var/run/named.pid` && echo -e "BIND9 stop\033[32m ok\033[0m"

}

 

case "$1" in

        start)

                START

                ;;

        stop)

                STOP

                ;;

        restart)

                STOP

                sleep 3

                START

                ;;

        *)

                echo "Usage: named (start|stop|restart)"

                ;;

esac

 

2、# chmod +x /etc/rc.d/init.d/named

 

3、# chkconfig --add named

 

4、# chkconfig named on

 

 

 

5、測試是否能正常使用

 

 

 

 

寫在最后:

1、  源碼安裝后dns的啟動方式:

service network start

2、  named主配置文件位置:

/usr/local/bind/etc/named.conf

3、  檢查主配置文件合法性的方式:

cd /usr/local/bind/sbin/

./named-checkconf ../etc/named.conf


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM