I'm running Bind and Apache on Debian and im doing dynamic updates on one of my zones with nsupdate via php script
The update Function:
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;
}
I call this function (sub = 'test', ip = random valid IPv4 IP):
$ret = nsupdate($sub, $ip);
if ($ret != 0) {
$msg = "Error! Code: $ret";
}else {
$msg = "Success!";
}
The value of $ret is '1' and the $msg is 'Error! Code: 1', but the syslog shows
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
i can ping the subdomain and it returns the new IP. But i'd still like to know why the nsupdate call returns 1 and not the expected 0 on a succesful update.
update 1 here the $cmdout with debugging enabled for nsupdate
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) "" }