分类:
2008-06-02 08:31:46
tar zxvf bind-9.3.2-P1.tar.gz
cd bind-9.3.2-P1
./configure --prefix=/usr/local/named --enable-threads --disable-openssl-version-check
或者
./configure --prefix=/usr/local/named --enable-threads --with-openssl=/usr/local/openssl
make
make install
--enable-threads 开启多线程支持
groupadd bind
useradd -g bind -d /usr/local/named -s /sbin/nologin bind
cd /usr/local/named
mkdir etc
sbin/rndc-confgen > etc/rndc.conf
cd etc
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
mkdir /usr/local/named/var
chmod 777 /usr/local/named/var
cd /usr/local/named/var
vi localhost.zone
$TTL 86400
$ORIGIN localhost.
@ 1D IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN NS @
1D IN A 127.0.0.1
建立named.local文件
vi named.local
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
dig命令直接生成named.root文件
dig > named.root
vi common.zone
内容如下
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; };
};
vi /usr/local/named/etc/named.conf
主要内容如下
options {
directory "/usr/local/named/var";
pid-file "named.pid";
version "I am bind";
listen-on {x.x.x.x;};
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};
include "common.zone";
chown -R bind:bind /usr/local/named
启动服务测试一下
/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf -u bind &
查看状态
/usr/local/named/sbin/rndc status
为了方便建立启动脚本:
vi /etc/rc.d/init.d/named
#!/bin/bash
# named a network name service.
# chkconfig: 545 35 75
# description: a name server
if [ `id -u` -ne 0 ]
then
echo "ERROR:For bind to port 53,must run as root."
exit 1
fi
case "$1" in
start)
if [ -x /usr/local/named/sbin/named ]; then
/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf -u bind && echo . && echo 'BIND9 server started'
fi
;;
stop)
kill `cat /usr/local/named/var/named.pid` && echo . && echo 'BIND9 server stopped'
;;
restart)
echo .
echo "Restart BIND9 server"
$0 stop
sleep 10
$0 start
;;
reload)
/usr/local/named/sbin/rndc reload
;;
status)
/usr/local/named/sbin/rndc status
;;
*)
echo "$0 start | stop | restart |reload |status"
;;
esac
chmod 755 /etc/rc.d/init.d/named
***********************************************************************
***********************************************************************
加入log配置
mkdir /usr/local/named/log
vi /usr/local/named/var/log.conf
logging {
channel warning
{ file "/usr/local/named/log/dns_warnings" versions 3 size 100m;
severity warning;
print-category yes;
print-severity yes;
print-time yes;
};
channel general_dns
{ file "/usr/local/named/log/dns_logs" versions 3 size 100m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
category default { warning; };
category queries { general_dns; };
};
chown -R bind:bind /usr/local/named
说明:
1:print-time是设定在日志中是否需要写入时间,print-severity是设定在日志中是否需要写入消息级别,print-category是设定在日志中是否需要写入日志类别。
2:severity是指定记录消息的级别。在bind中主要有以下几个级别(按照严重性递减的顺序):
critical
error
warning
notice
info
debug [ level ]
dynamic
定义了某个级别后,系统会记录包括该级别以及比该级别更严重的级别的所有消息。比如定义级别为error,则会记录critical和error两个级别的信息。一般情况下,我们记录到info级别就可以了。
然后在/usr/local/named/etc/named.conf 加入下列语句
include "log.conf";
/usr/local/named/sbin/rndc reconfig
默认是不启用日志的,你可以通过
/usr/local/named/sbin/rndc status
看到:
query logging is OFF
所以我们用以下命令启用log日志
/usr/local/named/sbin/rndc querylog