在学习Bind过程中,发现一篇很好的文章,所以把它摘录下来,一方面方便自己日后的配置,另一方面也给大家一起学习学习。我的bind也是参考这篇文章来配置的。(原文地址:http://hi.baidu.com/chenshake/blog/item/162f03172220d7044b90a718.html)
ip:192.168.1.168
www.test.com 192.168.1.168
mail.test.com 192.168.1.168
ns1.test.com 192.168.1.168
cd bind-9.4.2
./configure --prefix=/usr/local/named && make && make install
groupadd bind
useradd -g bind -d /usr/local/named -s /sbin/nologin bind
cd /usr/local/named/etc
/usr/local/named/sbin/rndc-confgen > rndc.conf
cat rndc.conf > rndc.key
chmod 777 /usr/local/named/var
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
vi named.conf
添加下面内容(
directory "/usr/local/named/var"; //域名文件存放的绝对路径
pid-file "named.pid"; //如果bind启动,自动会在/usr/local/named/var目录生成一个named.pid文件,打开文件就是named进程的ID
};
type hint; //根域名服务器
file "named.root"; //存放在//usr/local/named/var目录,文件名为named.root
};
type master; //类型为主域名服务器
file "localhost.zone"; //本地正向解析的文件
allow-update { none; };
};
type master; //类型为主域名服务器
file "named.local"; //本地反向解析的文件
allow-update { none; };
};
type master;
file "test.com.zone"; //test.com域映射IP地址可在此文件编写
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" in { //反向解析
type master;
file "test.com.rev"; //存放反向解析的文件
allow-update { none; };
};
########################
dig @a.root-servers.net . ns > named.root
##########
$TTL 86400
$ORIGIN localhost.
@ 1D IN SOA @ root (
42 ; serial (d.
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN A 127.0.0.1
#############
###############
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
####################
4:test.com.zone
############
@ IN SOA ns1.test.com. root.test.com. (
2008050122 ; serial
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS ns1.test.com.
A 192.168.1.168
MX 10 mail.test.com.
www A 192.168.1.168
mail A 192.168.1.168
ns1 A 192.168.1.168
5:test.com.rev
#############
$TTL 86400
@ IN SOA ns1.test.com. root.test.com.(
20031001;
7200;
3600;
43200;
86400);
@ IN NS ns1.test.com.
168 IN PTR ns1.test.com.
##############
# named a network name service.
# chkconfig: 345 35 75
# description: a name server
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
四:启动测试
启动服务测试一下
/usr/local/named/sbin/named -c /usr/local/named/etc/named.conf -u bind &
查看状态