下載bind,我下載的是bind-9.3.1rc1.tar.gz 我下載的文件放在/root目錄下 進入目錄解壓縮 [root@linux root]#tar xfz bind-9.3.1rc1.tar.gz 進如剛解壓出來的目錄 [root@linux root]# cd bind-9.3.1rc1 編譯配置 [root@linux bind-9.3.1rc1]#./configure --prefix=/usr/local/named --enable-threads #--enable-threads開啓多線程處理能力 [root@linux bind-9.3.1rc1]#make [root@linux bind-9.3.1rc1]#make install 進入/usr/local/named 創建etc目錄 [root@linux bind-9.3.1rc1]#cd /usr/local/named [root@linux named]# mkdir etc 生成rndc控制命令的key文件 [root@linux named]# sbin/rndc-confgen > etc/rndc.conf 從rndc.conf文件中提取named.conf用的key root@linux named]# cd etc [root@linux etc]# tail -10 rndc.conf | head -9 | sed s/#\ //g >named.conf 自動在/usr/local/named/etc 生成named,conf文件 創建區文件目錄 [root@linux etc]# mkdir /var/named 進入/var/named [root@linux etc]# cd /var/named 創建localhost.zone文件 [root@linux named]#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文件 [root@linux named]#vi named.local $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 AAAA ::1 dig命令直接生成named.root文件 [root@linux named]#dig >named.root 創建test.com域名正向解析文件 [root@linux named]#vi test.zone $ttl 1D @ IN SOA test.com. root.test.com. ( 1053891162 3H 15M 1W 1D ) IN NS test.com. IN MX 5 test.com. www IN A 220.202.19.82 創建test.com域名反向解析文件 [root@linux named]#vi test.local $TTL 86400 @ IN SOA test.com. root.test.com.( 20031001; 7200; 3600; 43200; 86400); @ IN NS test.com. 82 IN PTR dns.test.com. 配置named.conf加如如下代碼 [root@linux etc]# vi named.conf options { directory "/var/named"; #named區文件目錄 pid-file "named.pid"; #進程id文件名 }; controls { inet 127.0.0.1 allow { localhost; } keys { rndc-key; }; }; 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 "33.168.192.in-addr.arpa" IN { type master; file "test.local"; allow-update { none; }; }; 如今配置完了能夠啓動BIND了 /usr/local/named/sbin/named -c /usr/local/named/etc/named.conf & 報錯: v-dev-redis01:/usr/local/named/etc# tail -100 /var/log/messages Jun 26 14:04:26 v-dev-redis01 named[31466]: ---------------------------------------------------- Jun 26 14:04:26 v-dev-redis01 named[31466]: BIND 9 is maintained by Internet Systems Consortium, Jun 26 14:04:26 v-dev-redis01 named[31466]: Inc. (ISC), a non-profit 501(c)(3) public-benefit Jun 26 14:04:26 v-dev-redis01 named[31466]: corporation. Support and training for BIND 9 are Jun 26 14:04:26 v-dev-redis01 named[31466]: available at https://www.isc.org/support Jun 26 14:04:26 v-dev-redis01 named[31466]: ---------------------------------------------------- Jun 26 14:04:26 v-dev-redis01 named[31466]: adjusted limit on open files from 65535 to 1048576 Jun 26 14:04:26 v-dev-redis01 named[31466]: found 1 CPU, using 1 worker thread Jun 26 14:04:26 v-dev-redis01 named[31466]: using 1 UDP listener per interface Jun 26 14:04:26 v-dev-redis01 named[31466]: using up to 4096 sockets Jun 26 14:04:26 v-dev-redis01 named[31466]: loading configuration from '/usr/local/named/etc/named.conf' Jun 26 14:04:26 v-dev-redis01 named[31466]: /usr/local/named/etc/named.conf:15: unknown key 'rndckey' Jun 26 14:04:26 v-dev-redis01 named[31466]: loading configuration: failure Jun 26 14:04:26 v-dev-redis01 named[31466]: exiting (due to fatal error) 在添加一個zjtest3的域名: v-dev-redis01:/usr/local/named/etc# cat named.conf 加入 zone "zjtest3.com" IN { type master; file "zjtest3.zone"; allow-update { none; }; }; 添加: v-dev-redis01:/var/named# cat zjtest3.zone $TTL 1D @ IN SOA zjtest3.com. rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 AAAA ::1 www IN A 192.168.32.173 訪問外網報錯: v-dev-redis01:/usr/local/named/etc# tail -f /var/log/messages Jun 26 14:46:29 v-dev-redis01 named[3378]: client 192.168.33.29#61819 (www.baidu.com): query (cache) 'www.baidu.com/A/IN' denied Jun 26 14:46:29 v-dev-redis01 named[3378]: client 192.168.33.29#51412 (tip.f.360.cn): query (cache) 'tip.f.360.cn/A/IN' denied Jun 26 14:46:31 v-dev-redis01 named[3378]: client 192.168.33.29#63190 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:46:38 v-dev-redis01 named[3378]: client 192.168.33.29#54703 (www.baidu.com): query (cache) 'www.baidu.com/A/IN' denied Jun 26 14:46:38 v-dev-redis01 named[3378]: client 192.168.33.29#59213 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:46:38 v-dev-redis01 named[3378]: client 192.168.33.29#52891 (s.qhupdate.com): query (cache) 's.qhupdate.com/A/IN' denied Jun 26 14:46:38 v-dev-redis01 named[3378]: client 192.168.33.29#63828 (p0.qhimg.com): query (cache) 'p0.qhimg.com/A/IN' denied Jun 26 14:46:41 v-dev-redis01 named[3378]: client 192.168.33.29#61930 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:46:44 v-dev-redis01 named[3378]: client 192.168.33.29#53316 (s.qhupdate.com): query (cache) 's.qhupdate.com/A/IN' denied Jun 26 14:46:44 v-dev-redis01 named[3378]: client 192.168.33.29#50529 (p0.qhimg.com): query (cache) 'p0.qhimg.com/A/IN' denied Jun 26 14:46:48 v-dev-redis01 named[3378]: client 192.168.33.29#60619 (se.360.cn): query (cache) 'se.360.cn/A/IN' denied Jun 26 14:46:48 v-dev-redis01 named[3378]: client 192.168.33.29#58231 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:46:50 v-dev-redis01 named[3378]: client 192.168.33.29#56891 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:46:54 v-dev-redis01 named[3378]: client 192.168.33.29#53647 (se.360.cn): query (cache) 'se.360.cn/A/IN' denied Jun 26 14:46:56 v-dev-redis01 named[3378]: client 192.168.33.29#49777 (p0.qhimg.com): query (cache) 'p0.qhimg.com/A/IN' denied Jun 26 14:46:58 v-dev-redis01 named[3378]: client 192.168.33.29#49514 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:47:00 v-dev-redis01 named[3378]: client 192.168.33.29#65498 (imgcache.qq.com): query (cache) 'imgcache.qq.com/A/IN' denied Jun 26 14:47:01 v-dev-redis01 named[3378]: client 192.168.33.29#54451 (s.qhupdate.com): query (cache) 's.qhupdate.com/A/IN' denied zjtest7-app:/usr/local/named/etc# vim named.conf options { directory "/var/named"; #named區文件目錄 pid-file "named.pid"; #進程id文件名 allow-query { any; }; }; /***** zjtest7-app:/usr/local/named/etc# vim named.conf key "rndc-key" { algorithm hmac-md5; secret "08s1EL+uXQtvM7VOE4Kvbw=="; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; options { directory "/var/named"; #named??錄鎂目錄 pid-file "named.pid"; #陸酶?錄鎂? allow-query { any; }; }; zone "zjtest.com" IN { type master; file "zjtest.com.zone"; allow-update { none; }; }; zjtest7-app:/var/named# cat zjtest.com.zone $TTL 1D @ IN SOA zjtest.com. rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 AAAA ::1 www IN A 192.168.32.1 redis IN A 192.168.32.2 image IN A 192.168.32.3 db IN A 192.168.32.4 paydb IN A 192.168.32.5 C:\>ping redis.zjtest.com 正在 Ping redis.zjtest.com [192.168.32.2] 具備 32 字節的數據: Control-C ^C C:\>ping image.zjtest.com 正在 Ping image.zjtest.com [192.168.32.3] 具備 32 字節的數據: Control-C ^C C:\>ping db.zjtest.com 正在 Ping db.zjtest.com [192.168.32.4] 具備 32 字節的數據: Control-C ^C C:\>ping paydb.zjtest.com 正在 Ping paydb.zjtest.com [192.168.32.5] 具備 32 字節的數據: 來自 192.168.32.5 的回覆: 字節=32 時間=4ms TTL=63 192.168.32.5 的 Ping 統計信息: 數據包: 已發送 = 1,已接收 = 1,丟失 = 0 (0% 丟失), 往返行程的估計時間(以毫秒爲單位): 最短 = 4ms,最長 = 4ms,平均 = 4ms Control-C ^C C:\>