我在 Debian 上运行 Bind 和 Apache,我通过 php 脚本使用 nsupdate 在我的一个区域上进行动态更新
更新功能:
function nsupdate($subdomain, $ip) {
$domain = escapeshellcmd($subdomain . '.example.com');
$ip = escapeshellcmd($ip);
$data = "<<EOF
server localhost
zone example.com
update delete $domain A
update add $domain 10 A $ip
send
EOF";
exec("/usr/bin/nsupdate -k /var/bind/keys/Kexample.com.+157+40387.private $data", $cmdout, $ret);
return $ret;
}
我调用这个函数(sub = 'test', ip = random valid IPv4 IP):
$ret = nsupdate($sub, $ip);
if ($ret != 0) {
$msg = "Error! Code: $ret";
}else {
$msg = "Success!";
}
$ret 的值为 '1' 而 $msg 是 'Error! 代码:1',但系统日志显示
client ::1#9726/key example.com: signer "example.com" approved
client ::1#9726/key example.com: updating zone 'example.com/IN': deleting rrset at 'test.example.com' A
client ::1#9726/key example.com: updating zone 'example.com/IN': adding an RR at 'test.example.com' A
我可以 ping 子域,它会返回新的 IP。但我仍然想知道为什么 nsupdate 调用在成功更新时返回 1 而不是预期的 0。
在此处更新 1 为 nsupdate 启用调试的 $cmdout
array(13) {
[0]=> string(22) "Outgoing update query:"
[1]=> string(59) ";; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id: 58402"
[2]=> string(55) ";; flags:; ZONE: 1, PREREQ: 0, UPDATE: 2, ADDITIONAL: 1"
[3]=> string(16) ";; ZONE SECTION:"
[4]=> string(22) ";example.com. IN SOA"
[5]=> string(0) ""
[6]=> string(18) ";; UPDATE SECTION:"
[7]=> string(33) "test.example.com. 0 ANY A"
[8]=> string(45) "test.example.com. 10 IN A 22.22.22.22"
[9]=> string(0) ""
[10]=> string(22) ";; TSIG PSEUDOSECTION:"
[11]=> string(109) "example.com. 0 ANY TSIG hmac-md5.sig-alg.reg.int. 1439217988 300 16 kaHm1/GbMf0+cuIJO62lgw== 58402 NOERROR 0"
[12]=> string(0) "" }