设置绑定以使用nsupdate(SERVFAIL)

我正在尝试使用nsupdatedynamic更新我的DNS服务器。

条件

我在我的客户端的DNS服务器和Debian 4上使用Debian 6。

我创build了一个公钥/私钥对,使用:

dnssec-keygen -C -a HMAC-MD5 -b 512 -n USER sub.example.com. 

然后,我编辑我的named.conf.local来包含我的公钥和我想更新的新区域。 它现在看起来像这样(注意:我也尝试了allow-update {any;};没有成功):

 zone "example.com" { type master; file "/etc/bind/primary/example.com"; notify yes; allow-update { none; }; allow-query { any; }; }; zone "sub.example.com" { type master; file "/etc/bind/primary/sub.example.com"; notify yes; allow-update { key "sub.example.com."; }; allow-query { any; }; }; key sub.example.com. { algorithm HMAC-MD5; secret "xxxx xxxx"; }; 

接下来,我将私钥文件( key.private )复制到另一个我想更新区域的服务器。 我还在这个服务器上创build了一个包含更新信息的文本文件( 更新 )(注意:我也尝试过使用这个东西,没有成功):

 server example.com zone sub.example.com update add sub.example.com. 86400 A 10.10.10.1 show send 

现在我试图更新区域使用:

 nsupdate -k key.private -v update 

问题

所述命令给我以下输出:

 Outgoing update query: ;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id: 0 ;; flags: ; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0 ;; ZONE SECTION: ;sub.example.com. IN SOA ;; UPDATE SECTION: sub.example.com. 86400 IN A 10.10.10.1 update failed: SERVFAIL 

当我在远程服务器上发出nsupdate命令时,名为debug的Level 3给了我下面的信息(注意:我模糊了客户端IP):

 06-Aug-2012 14:51:33.977 client XXXX#33182: new TCP connection 06-Aug-2012 14:51:33.977 client XXXX#33182: replace 06-Aug-2012 14:51:33.978 clientmgr @0x2ada3c7ee760: createclients 06-Aug-2012 14:51:33.978 clientmgr @0x2ada3c7ee760: recycle 06-Aug-2012 14:51:33.978 client @0x2ada475f1120: accept 06-Aug-2012 14:51:33.978 client XXXX#33182: read 06-Aug-2012 14:51:33.978 client XXXX#33182: TCP request 06-Aug-2012 14:51:33.978 client XXXX#33182: request has valid signature 06-Aug-2012 14:51:33.978 client XXXX#33182: recursion not available 06-Aug-2012 14:51:33.978 client XXXX#33182: update 06-Aug-2012 14:51:33.978 client XXXX#33182: send 06-Aug-2012 14:51:33.978 client XXXX#33182: sendto 06-Aug-2012 14:51:33.979 client XXXX#33182: senddone 06-Aug-2012 14:51:33.979 client XXXX#33182: next 06-Aug-2012 14:51:33.979 client XXXX#33182: endrequest 06-Aug-2012 14:51:33.979 client XXXX#33182: read 06-Aug-2012 14:51:33.986 client XXXX#33182: next 06-Aug-2012 14:51:33.986 client XXXX#33182: request failed: end of file 06-Aug-2012 14:51:33.986 client XXXX#33182: endrequest 06-Aug-2012 14:51:33.986 client XXXX#33182: closetcp 

但它什么都不做。 该区域不会更新,我的nsupdate也不会更改任何内容。 我不确定在第一次更新之前,文件/etc/bind/primary/sub.example.com是否应该存在。 我试过没有文件,一个空文件和一个预先configuration的区域文件。 没有成功。

我在网上发现的稀疏信息指向了关于绑定工作目录的文件和文件夹权限,所以我改变了/ etc / bind/ var / cache / bind的权限(这是我的“绑定”用户)。

我不是100%的确定,如果权限是正确的..但它看起来不错,对我来说:

 ls -lah /var/cache/bind/ total 224K drwxrwxr-x 2 bind bind 4.0K Aug 6 03:13 . drwxr-xr-x 12 root root 4.0K Jul 21 11:27 .. -rw-r--r-- 1 bind bind 211K Aug 6 03:21 named.run ls -lah /etc/bind/ total 72K drwxr-sr-x 3 bind bind 4.0K Aug 6 14:41 . drwxr-xr-x 87 root root 4.0K Jul 30 01:24 .. -rw------- 1 bind bind 125 Aug 6 02:54 key.public -rw------- 1 bind bind 156 Aug 6 02:54 key.private -rw-r--r-- 1 bind bind 2.5K Aug 6 03:07 bind.keys -rw-r--r-- 1 bind bind 237 Aug 6 03:07 db.0 -rw-r--r-- 1 bind bind 271 Aug 6 03:07 db.127 -rw-r--r-- 1 bind bind 237 Aug 6 03:07 db.255 -rw-r--r-- 1 bind bind 353 Aug 6 03:07 db.empty -rw-r--r-- 1 bind bind 270 Aug 6 03:07 db.local -rw-r--r-- 1 bind bind 3.0K Aug 6 03:07 db.root -rw-r--r-- 1 bind bind 493 Aug 6 03:32 named.conf -rw-r--r-- 1 bind bind 490 Aug 6 03:07 named.conf.default-zones -rw-r--r-- 1 bind bind 1.2K Aug 6 14:18 named.conf.local -rw-r--r-- 1 bind bind 666 Jul 29 22:51 named.conf.options drwxr-sr-x 2 bind bind 4.0K Aug 6 03:57 primary/ -rw-r----- 1 root bind 77 Mar 19 02:57 rndc.key -rw-r--r-- 1 bind bind 1.3K Aug 6 03:07 zones.rfc1918 ls -lah /etc/bind/primary/ total 20K drwxr-sr-x 2 bind bind 4.0K Aug 6 03:57 . drwxr-sr-x 3 bind bind 4.0K Aug 6 14:41 .. -rw-r--r-- 1 bind bind 356 Jul 30 00:45 example.com 

我在Ubuntu服务器上遇到了几乎完全相同的问题,结果是两个问题:

(1)装饰

我不知道Debian是否也是这样,但是Ubuntu的bind9是启用apparmor的。 这意味着只允许写入某些地方。 这些地方列在/etc/apparmor.d/usr.sbin.named ,通常build议保留在这些目录中。 你可以安装apparmor-utils软件包,并(临时)禁用apparmor进行绑定,看看是否会导致你的问题:

 sudo aa-status 

应在强制configuration文件列表中显示/usr/sbin/named 。 然后运行

 sudo aa-complain /usr/sbin/named 

把它放入抱怨模式。

(2)区域文件

几乎没有手册/教程提到这一点,但bind9期望(预)现有的区域文件正常工作。 end of file错误的end of file可能是由于区域文件尚不存在(您的示例中的/etc/bind/primary/example.com/etc/bind/primary/sub.example.com导致的。 你可以简单地创build一个像这样的:

 echo "; DO NOT EDIT MANUALLY - use the \"nsupdate\" utility to prevent data loss ; \$ORIGIN example.com. \$TTL 86400 ; 1 day @ IN SOA ns1.example.com. hostmaster.example.com. ( 2009074711 ; serial 7200 ; refresh (2 hours) 300 ; retry (5 minutes) 604800 ; expire (1 week) 60 ; minimum (1 minute) ) IN NS ns1.example.com. ns1 IN A <IP of your bind server>" | sudo -u bind tee /etc/bind/primary/example.com 

请参阅nsupdate中的部分

  With the -k option, nsupdate reads the shared secret from the file keyfile. Keyfiles may be in two formats: a single file containing a named.conf-format key statement, which may be generated automatically by ddns-confgen, or a pair of files whose names are of the format K{name}.+157.+{random}.key and K{name}.+157.+{random}.private, which can be generated by dnssec-keygen. The -k may also be used to specify a SIG(0) key used to authenticate Dynamic DNS update requests. In this case, the key specified is not an HMAC-MD5 key. 

所以如果你想把它重新格式化成

 key sub.example.com. { algorithm HMAC-MD5; secret "xxxx xxxx"; }; 

形成并保留在文件中,它将起作用,或者select-k K{name}.+157.+{random}.*

对于dyndns更新,BIND必须能够写入区域使用的文件夹。 在我看来,/ etc是不是一个正确的地方来存储这样的信息,并看着你的权限等是不能通过绑定写入。

我build议尝试/ var / bind目录,以便绑定可以写入它。