dns安裝配置小結

1.          http://www.isc.org下載最新版本bind-9.8.1.tar.gzide

 

2.         安裝須要openssl支持工具

yum –y install openssl-devel測試

 

3.         編譯安裝bind-9.8.1.tar.gzspa

tar zxvf bind-9.8.1.tar.gz.net

cd bind-9.8.1rest

./configure --prefix=/usr/local/named --enable-threads --with-libtoolorm

make && make installserver

 

4.          生成rndc控制命令的key文件dns

cd /usr/local/named進程

sbin/rndc-confgen >etc/rndc.conf

 

5.          rndc.conf文件中提取named.conf用的key 生存named.conf

cd /usr/local/named/etc

tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf 

 

6.           創建zone文件目錄

mkdir /usr/local/named/data

cd /usr/local/named/data

 

7.          創建localhost.zone文件

$TTL    86400

$ORIGIN localhost.

@  IN SOA localhost. root.localhost. (

20111025

259200

172800

604800

86400 )

 

@  1D IN NS        localhost.

     1D IN A         127.0.0.1         

8.          創建named.local文件

$TTL    86400

@       IN      SOA     localhost. root.localhost.  (

                                      19970227 ; Serial

                                      28800      ; Refresh

                                      14400      ; Retry

                                      3600000    ; Expire

                                      86400 )    ; Minimum

              IN      NS      localhost.

1       IN      PTR     localhost.

9.          創建named.root文件

wget  http://www.internic.net/zones/named.root

10.      創建test.com域名正向解析文件

$TTL 86400

@ IN SOA test.com. root.test.com. (

20110619

28800 ; Refresh

14400 ; Retry

3600000 ; Expire

86400 ) ; Minimum

    IN NS ns1.test.com.

www IN A 100.100.100.100

ns1 IN A 127.0.0.1

                 

11.      創建域名反向解析文件test.local

$TTL 86400

@ IN SOA test.com. root.test.com. (

20031001;

7200;

3600;

43200;

86400 );

@ IN NS test.com.

100 IN PTR dns.test.com.

12.      配置named.conf加如如下代碼

key "rndc-key" {

        algorithm hmac-md5;

        secret "WRWEgoU2KodRUovkmhnE7w==";

};

 

options {

        directory "/usr/local/named/data"; #named區文件目錄 

        pid-file "named.pid"; #進程id文件名 

};

 

#controls {

#        inet 127.0.0.1 allow {localhost;} keys { "rndc-key"; };

#};

 

#disabled rndc 工具

controls {};

 

zone "." IN {

        type hint;

        file "named.root";

};

 

zone "localhost" IN {

        type master;

        file "localhost.zone";

        allow-update { none; };

};

 

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

        type master;

        file "named.local";

        allow-update { none; };

};

 

zone "test.com" IN {

        type master;

        file "test.zone";

        allow-update { none; };

};

 

 

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

        type master;

        file "test.local";

        allow-update { none; };

};

13.      查看啓動是否有錯誤

/usr/local/named/sbin/named –g

若是提示缺乏managed-keys.bind

touch /usr/local/named/data/managed-keys.bind

啓動named進程

/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf &

14.      測試解析

配置/etc/resolve.conf nameservers 127.0.0.1

nslookup www.test.com

    host 100.100.100.100

 

15.         編輯啓動腳本/etc/init.d/named

#!/bin/sh

 

DESC="named daemon"

NAME=named

DAEMON=/usr/local/named/sbin/$NAME

CONFIGFILE=/usr/local/named/etc/named.conf

PIDFILE=/usr/local/named/etc/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

 

d_start() {

  if [ ! -f $PIDFILE ]

  then $DAEMON -c $CONFIGFILE >/dev/null 2>&1

  else echo " $DESC is already running"

  exit 0

  fi

}

 

d_stop() {

  if [ ! -f $PIDFILE ]

  then echo " $DESC is not running"

  exit 0

  else kill -15 `cat $PIDFILE` >/dev/null 2>&1

  fi

}

 

 

d_reload() {

  if [ ! -f $PIDFILE ]

  then echo "$DESC can't reload"

  exit 0

  else kill -HUP `cat $PIDFILE` >/dev/null 2>&1

  fi

}

 

 

case "$1" in

  start)

        echo -n "Starting $DESC..."

        d_start

        echo -e "\033[032m OK!\033[0m"

        ;;

  stop)

        echo -n "Stopping $DESC..."

        d_stop

        echo -e "\033[032m OK!\033[0m"

        ;;

  reload)

        echo -n "Reloading $DESC..."

        d_reload

        echo -e "\033[032m OK!\033[0m"

        ;;

  restart)

        echo -n "Restarting $DESC..."

        if [ ! -f $PIDFILE ]

        then d_start

        echo -e "\033[032m OK!\033[0m"

        else d_stop

        sleep 1

        d_start

        echo -e "\033[032m OK!\033[0m"

        fi

        ;;

  *)

          echo -e "\033[031m Usage: $SCRIPTNAME {start|stop|restart|reload} \033[0m" >&2

          exit 3

        ;;

esac

exit 0

相關文章
相關標籤/搜索