3.bind-utils是bind软件提供的一组DNS工具包,里面有一些DNS相关的工具。主要:dig,host,nslookup,nsupdate。使用这些工具可以进行域名解析和DNS调试工作。
4.caching-nameserver提供构建缓存域名服务器的基本配置文件,这些文件在构建主从域名时可以作为参考。
一、安装
yum -y install gcc-c++ openssl openssl-devel
wget ftp://ftp.isc.org/isc/bind9/9.9.7/bind-9.9.7.tar.gz
mkdir bind9.9.7
tar -zxvf bind-9.9.7.tar.gz
cd bind-9.9.7
./configure --enable-largefile --enable-threads --disable-openssl-version-check --prefix=/home/slim/bind9.9.7 --with-libtool
make
make install
为了方便升级,建立软连接
ln -s /home/slim/bind9.9.7/ ./bind
查看安装版本:
./bind/sbin/named -v
对于.configure参数的说明:
--prefix=/usr/local/bind 指定bind9的安装目录,默认是/usr/local
--enable-threads 开启多线程的支持;如果你的系统有多个CPU,那么可以使用这个选项
--disable-openssl-version-check 关闭openssl的检查
--with-openssl=/usr/local/openssl 指定openssl的安装路径
--sysconfdir=/etc 设置named.conf配置文件放置的目录,默认是--prefix选项指定的目录下的/etc下
--localstatdir=/var 设置 run/named.pid 放置的目录,默认是--prefix选项指定的目录下的/var下
--with-libtool 将BIND的库文件编译为动态共享库文件,这个选项默认是未选择的。
如果不选这个选项,那么编译后的named命令会比较大,lib目录中的库文件都是.a后缀的
如果选上这个选项,那么编译后的named命令会很小,lib目录中的库文件则是.so后缀
二、配置
mkdir -p chroot/{etc,var,dev}
mkdir -p chroot/var/{named,run}
mkdir -p chroot/var/named/{zone,data,log,dynamic}
touch chroot/dev/random
cd chroot/etc
1.生成rndc控制命令的key文件
bind9 规定,如果要使用rndc 来控制dns 。必须先生成验证文件rndc.conf和密锁
/home/slim/bind/sbin/rndc-confgen > /home/slim/chroot/etc/rndc.conf
2.生成named.conf
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
修改配置named.conf:
key "rndc-key" { algorithm hmac-md5; secret "WTHTSrZYMNFPjOGjMUHQUQ=="; }; controls { inet 127.0.0.1 port 6953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; options{ listen-on port 6053{ 192.168.13.102; }; version "vdns3.0"; directory "/home/slim/chroot/var/named"; pid-file "/home/slim/chroot/var/run/named.pid"; session-keyfile "/home/slim/chroot/var/run/session.key"; dump-file "/home/slim/chroot/var/named/data/cache_dump.db"; statistics-file "/home/slim/chroot/var/named/data/named_stats.txt"; memstatistics-file "/home/slim/chroot/var/named/data/named_mem_stats.txt"; allow-query{ any; }; allow-query-cache{ any; }; allow-transfer{ none; }; /* Path to ISC DLV key */ bindkeys-file "/home/slim/chroot/etc/named.iscdlv.key"; managed-keys-directory "/home/slim/chroot/var/named/dynamic"; }; logging { channel default_debug { file "/home/slim/chroot/var/named/data/named.run"; severity dynamic; }; channel queries_info { file "/home/slim/chroot/var/named/log/query.log" versions 1 size 100m; severity info; print-category yes; print-severity yes; print-time yes; }; category queries { queries_info; default_debug; }; channel notify_info { file "/home/slim/chroot/var/named/log/notify.log" versions 8 size 128m; severity info; print-category yes; print-severity yes; print-time yes; }; category notify { notify_info; default_debug; }; }; 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"; allow-update { none; }; }; zone "test.com" IN { type master; file "zone/test.com.zone"; };
3.下载named.root配置文件
cd chroot/var/named
$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 ::14.创建文件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.
cd zone
5.创建test.com.zone
$TTL 86400 @ IN SOA test.com. admin.test.com. ( 57 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum IN NS dns.test.com. IN MX 5 mail dns IN A 192.168.13.102 mail IN A 192.168.13.102 www IN A 192.168.100.90注意:bind的配置文档是区分大小写的。
检测主配置文件内容
./bind/sbin/named-checkconf ./chroot/etc/named.conf
测试正向区域文件
./bind/sbin/named-checkzone localhost. chroot/var/named/localhost.zone
测试反向区域文件
./bind/sbin/named-checkzone 127.0.0.1 chroot/var/named/localhost.rev
./bind/sbin/named-checkzone test.com. chroot/var/named/zone/test.com.zone
三、启动
/home/slim/bind/sbin/named -gc /home/slim/chroot/etc/named.conf &
此处启动了调试,有问题会打印出出错信息。当调试正常后启动需要去掉g这个参数。
查看dns服务是否启动,端口是否激活:
netstat -an | grep :6053
查看运行状态:
/home/slim/bind/sbin/rndc -c /home/slim/chroot/etc/rndc.conf -s 127.0.0.1 -p 6953 status version: 9.9.7 (vdns3.0) <id:e87fa9ae> CPUs found: 1 worker threads: 1 UDP listeners per interface: 1 number of zones: 101 debug level: 0 xfers running: 0 xfers deferred: 0 soa queries in progress: 0 query logging is ON recursive clients: 0/0/1000 tcp clients: 0/100 server is up and running
四、测试
dig @192.168.13.102 -p 6053 www.test.com
14-Apr-2015 08:13:19.615 client 192.168.36.54#45767 (www.test.com): query: www.test.com IN A + (192.168.36.54) ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> @192.168.36.54 -p 6053 www.test.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14708 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;www.test.com. IN A ;; ANSWER SECTION: www.test.com. 86400 IN A 192.168.100.90 ;; AUTHORITY SECTION: test.com. 86400 IN NS dns.test.com. ;; ADDITIONAL SECTION: dns.test.com. 86400 IN A 192.168.13.102 ;; Query time: 2 msec ;; SERVER: 192.168.36.54#6053(192.168.36.54) ;; WHEN: Tue Apr 14 08:13:19 2015 ;; MSG SIZE rcvd: 80
参考文章:
BIND配置文件详解