昨天我剛剛在非生產(chǎn)環(huán)境中的Red Hat Enterprise Linux Server上配置了一臺(tái)DNS服務(wù)器,以做測試使用。但是很快遇到了一個(gè)奇怪的錯(cuò)誤。
我在執(zhí)行“service named status”后,其中第一行顯示如下內(nèi)容:
01.[root@localhost ~]# service named status
02.rndc: connect failed: 127.0.0.1#953: connection refused
03.named (pid 6207) is running...
04.[root@localhost ~]#
首先不是權(quán)限的問題。我查看了所有DNS相關(guān)的所有配置文件,展示如下,也為大家以后出錯(cuò)作為參考。因?yàn)槭褂胷oot登錄終端對(duì)文件或目錄執(zhí)行移動(dòng)或創(chuàng)建工作很容易導(dǎo)致權(quán)限問題。
01.[root@localhost ~]# ls /var/named/ -al
02.total 40
03.drwxr-x---. 6 root named 4096 Mar 28 13:05 .
04.drwxr-xr-x. 28 root root 4096 Mar 28 13:44 ..
05.drwxr-x---. 6 root named 4096 Mar 28 13:05 chroot
06.drwxrwx---. 2 named named 4096 Mar 28 13:23 data
07.drwxrwx---. 2 named named 4096 Mar 28 15:24 dynamic
08.-rw-r-----. 1 root named 1892 Feb 18 2008 named.ca
09.-rw-r-----. 1 root named 152 Dec 15 2009 named.empty
10.-rw-r-----. 1 root named 152 Jun 21 2007 named.localhost
11.-rw-r-----. 1 root named 168 Dec 15 2009 named.loopback
12.drwxrwx---. 2 named named 4096 Dec 20 23:53 slaves
13.[root@localhost ~]# ls /var/named/chroot/ -al
14.total 24
15.drwxr-x---. 6 root named 4096 Mar 28 13:05 .
16.drwxr-x---. 6 root named 4096 Mar 28 13:05 ..
17.drwxr-x---. 2 root named 4096 Mar 28 13:05 dev
18.drwxr-x---. 4 root named 4096 Mar 28 14:32 etc
19.drwxr-xr-x. 3 root root 4096 Mar 28 13:05 usr
20.drwxr-x---. 6 root named 4096 Mar 28 13:05 var
21.[root@localhost ~]# ls /var/named/chroot/etc/ -al
22.total 40
23.drwxr-x---. 4 root named 4096 Mar 28 14:32 .
24.drwxr-x---. 6 root named 4096 Mar 28 13:05 ..
25.-rw-r--r--. 1 root root 405 Oct 19 22:00 localtime
26.drwxr-x---. 2 root named 4096 Dec 20 23:53 named
27.-rw-r-----. 1 root named 1259 Mar 28 14:31 named.conf
28.-rw-r--r--. 1 root named 2544 Dec 20 23:53 named.iscdlv.key
29.-rw-r-----. 1 root named 931 Jun 21 2007 named.rfc1912.zones
30.-rw-r--r--. 1 root named 487 Dec 20 23:53 named.root.key
31.drwxr-xr-x. 3 root root 4096 Mar 28 13:05 pki
32.-rw-------. 1 root root 479 Mar 27 23:46 rndc.conf
33.[root@localhost ~]# ls /var/named/chroot/var -al
34.total 24
35.drwxr-x---. 6 root named 4096 Mar 28 13:05 .
36.drwxr-x---. 6 root named 4096 Mar 28 13:05 ..
37.drwxrwx---. 2 named named 4096 Dec 20 23:53 log
38.drwxr-x---. 6 root named 4096 Mar 28 13:05 named
39.drwxr-x---. 3 root named 4096 Mar 28 13:05 run
40.drwxrwx---. 2 named named 4096 Dec 20 23:53 tmp
41.[root@localhost ~]# ls /etc/named* -al
42.-rw-r-----. 1 root named 1259 Mar 28 14:31 /etc/named.conf
43.-rw-r-----. 1 root root 930 Mar 28 13:41 /etc/named.conf.backup
44.-rw-r--r--. 1 root named 2544 Dec 20 23:53 /etc/named.iscdlv.key
45.-rw-r-----. 1 root named 931 Jun 21 2007 /etc/named.rfc1912.zones
46.-rw-r--r--. 1 root named 487 Dec 20 23:53 /etc/named.root.key
47.
48./etc/named:
49.total 16
50.drwxr-x---. 2 root named 4096 Dec 20 23:53 .
51.drwxr-xr-x. 131 root root 12288 Mar 28 14:32 ..
52.[root@localhost ~]# ls /etc/rndc.* -al
53.-rw-------. 1 root root 479 Mar 27 23:46 /etc/rndc.conf
54.-rw-------. 1 root root 479 Mar 28 13:42 /etc/rndc.conf.backup
55.-rw-------. 1 root root 479 Mar 27 23:10 /etc/rndc.conf.original
56.-rw-------. 1 root root 479 Mar 27 23:46 /etc/rndc.conf.original_1_error_secret
57.-rw-------. 1 root root 510 Mar 27 23:43 /etc/rndc.key.removed_no_need
58.-rw-------. 1 root root 511 Mar 27 23:50 /etc/rndc.key.removed_no_need_1
59.[root@localhost ~]#
第一段代碼:
01.[root@localhost ~]# cat /etc/named.conf
02.//
03.// named.conf
04.//
05.// Provided by Red Hat bind package to configure the ISC BIND named( DNS
06.// server as a caching only nameserver (as a localhost DNS resolver only).
07.//
08.// See /usr/share/doc/bind*/sample/ for example named configuration files.
09.//
10.
11.options {
12. listen-on port 53 { 127.0.0.1; };
13. listen-on-v6 port 53 { ::1; };
14. directory "/var/named";
15. dump-file "/var/named/data/cache_dump.db";
16. statistics-file "/var/named/data/named_stats.txt";
17. memstatistics-file "/var/named/data/named_mem_stats.txt";
18. allow-query { localhost; };
19. recursion yes;
20.
21. dnssec-enable yes;
22. dnssec-validation yes;
23. dnssec-lookaside auto;
24.
25. /* Path to ISC DLV key */
26. bindkeys-file "/etc/named.iscdlv.key";
27.};
28.
29.logging {
30. channel default_debug {
31. file "data/named.run";
32. severity dynamic;
33. };
34.};
35.
36.zone "." IN {
37. type hint;
38. file "named.ca";
39.};
40.
41.include "/etc/named.rfc1912.zones";
第二段代碼:
01.[root@localhost ~]# cat /etc/named.conf
02.//
03.// named.conf
04.//
05.// Provided by Red Hat bind package to configure the ISC BIND named( DNS
06.// server as a caching only nameserver (as a localhost DNS resolver only).
07.//
08.// See /usr/share/doc/bind*/sample/ for example named configuration files.
09.//
10.
11.options {
12. listen-on port 53 { 127.0.0.1; };
13. listen-on-v6 port 53 { ::1; };
14. directory "/var/named";
15. dump-file "/var/named/data/cache_dump.db";
16. statistics-file "/var/named/data/named_stats.txt";
17. memstatistics-file "/var/named/data/named_mem_stats.txt";
18. allow-query { localhost; };
19. recursion yes;
20.
21. dnssec-enable yes;
22. dnssec-validation yes;
23. dnssec-lookaside auto;
24.
25. /* Path to ISC DLV key */
26. bindkeys-file "/etc/named.iscdlv.key";
27.};
28.
29.logging {
30. channel default_debug {
31. file "data/named.run";
32. severity dynamic;
33. };
34.};
35.
36.zone "." IN {
37. type hint;
38. file "named.ca";
39.};
40.
41.include "/etc/named.rfc1912.zones";
42.# Add line to enable named working with "/etc/rndc.conf"
43.
44.# Use with the following in named.conf, adjusting the allow list as needed:
45.key "rndc-key" {
46. algorithm hmac-md5;
47. secret "cK1Bt77B8kL9uLpxy4GDTg==";
48.};
49.
50.controls {
51. inet 127.0.0.1 port 953
52. allow { 127.0.0.1; } keys { "rndc-key"; };
53.};
54.# End of named.conf
55.
56.[root@localhost ~]#
最后,重新啟動(dòng)named守護(hù)進(jìn)程
01.su -
02.service named restart
03.service named status
結(jié)果顯示如下,就表示可以了。
01.[root@localhost ~]# service named status
02.version: 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.2
03.CPUs found: 2
04.worker threads: 2
05.number of zones: 19
06.debug level: 0
07.xfers running: 0
08.xfers deferred: 0
09.soa queries in progress: 0
10.query logging is OFF
11.recursive clients: 0/0/1000
12.tcp clients: 0/100
13.server is up and running
14.named (pid 1191 is running...
15.[root@localhost ~]#