一.下载最新的Bind发行版: ①.在根目录下创建一个名为software的文件夹并进入这个文件夹(此文件夹是为了放置下载的源码包和解压的文件): mkdir /software cd /software ②.下载bind.9.6.1的软件包: wget ftp://ftp.isc.org/isc/bind9/9.6.1/bind-9.6.1.tar.gz
二.软件安装: ①.解压该软件包并进入: tar zxvf bind-9.6.1.tar.gz cd bind-9.6.1 ②.指明路径并编译安装 ./configure --enable-largefile --enable-threads --prefix=/usr/local/named make make install
三.开始配置:
/usr/local/named/sbin/rndc-confgen > /usr/local/named/etc/rndc.conf cd /usr/local/named/etc tail -10 rndc.conf | head -9 | sed s/# //g > named.conf ①.下面再编辑named.conf文件并补充如下信息: vi /usr/local/named/etc/named.conf options { listen-on port 53 { 172.15.0.140; }; Directory "/usr/local/named"; Pid-file "named.pid"; Allow-query {any;}; Dump-file "/usr/local/named/data/cache_dump.db"; Statistics-file "/usr/local/named/data/named_stats.txt"; #forward only; forwarders {218.104.111.114;218.104.111.122;}; //设置转发的公网DNS服务器地址 #forwarders {202.103.24.68;202.103.44.150;}; #forwarders {172.18.0.6;}; //设置内网DNS服务器转发 #atcp-clients 10000; #listen-on { any;}; }; zone "." in { Type hint; File "named.root"; }; zone "localhost" in { Type master; File "localhost.zone"; }; zone "0.0.127.in-addr.arpa" in { Type master; File "localhost.rev"; }; cd /usr/local/named/ ②.在当前目录下增加几个文件: vi localhost.zone $TTL 86400 @ IN SOA @ root ( 42 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum IN NS @ IN A 127.0.0.1 IN AAAA ::1 vi localhost.rev $TTL 86400 @ IN SOA localhost. root.localhost. ( 1997022700 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum IN NS localhost. 1 IN PTR localhost. ③.下载named.root这个文件 wget ftp://ftp.rs.internic.net/domain/named.root 到此配置完成 三.测试bind启动: /usr/local/named/sbin/named -gc /usr/local/named/etc/named.conf 启动Bind: /usr/local/named/sbin/named -c /usr/local/named/etc/named.conf
此处启动了调试,有问题会打印出出错信息。当调试正常后启动需要去掉g这个参数。
四.配置named以服务启动 vi /etc/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 -u root -c /usr/local/named/etc/named.conf && echo 'start named [ok]' fi ;; stop) kill `cat /usr/local/named/named.pid` && echo 'stop named [ok]' ;; restart) echo "restart named" $0 stop $0 start ;; *) echo "$0 start | stop | restart" ;; esac
五.后续工作: ①.编辑/etc/resolv.conf这个文件(设置该服务器的DNS地址为本机IP): vim /etc/resolv.conf nameserver 172.15.0.140 ②.添加并设置named服务为开机启动: [root@localhost~]#cd /etc/init.d/ [root@localhost init.d]# chkconfig --add named /*将named添加到chkconfig管辖之内 [root@localhost init.d]# chkconfig named on /*启用这个服务 [root@localhost init.d]# chkconfig --list named /*显示 named
③.重启named服务:service named restart ***会发现该服务无法启动,原因是因为没有执行权限。 解决方法是:给予named这个文件执行的权限: cd /etc/init.d/ chmod 777 named 配置好权限之后再重启named服务就OK了...... ④.ping 218.104.111.114看通不通,测试能ping痛没问题了就用nslookup命令开始检测所搭建的DNS是否成功。 例如:nslookup >www.baidu.com >www.linuxidc.com >www.linuxidc.net ⑤.后期的使用过程中要养成利用查看日志的方法来排除问题的习惯,这样便于你快速方便的找到问题所在: tail -f /var/log/message