nsupdate 9.3.4 server servername
Kevin Darcy
kcd at daimlerchrysler.com
Sat Apr 28 00:43:37 UTC 2007
J.D. Bronson wrote:
> What is the correct syntax for using nsupdate with a different server
> via command line in 1 statement?
>
> No matter what I try, it only tries to update the MASTER one and not
> another one I am trying to test with:
>
> nsupdate -k /var/named/keys/Kns2.mydomain.com.+157+32453.private -d
> /etc/nsupdate server ns4.mydomain.com
>
>
> (/etc/nsupdate contains information to pass onto nsupdate from this script:)
>
> =============
> #!/sbin/sh
> IPADDR=`/sbin/ifconfig bge1|grep 'inet [0-9]'|tr -s " "|cut -d" " -f2`
> echo "update delete www.mydomain.com. A" > /etc/nsupdate
> echo "update add www.mydomain.com. 86400 IN A $IPADDR" >> /etc/nsupdate
> echo "" >> /etc/nsupdate
>
> =============
> My script works fine if I do not use the 'server' statement but I
> dont want to mess with production name servers until I have things
> perfect...so I know nothing is wrong with my script.
>
> How do I get nsupdate to talk to a different server?
>
Mark has already mentioned the "server" directive of nsupdate. But I
couldn't resist offering some coding improvements. For a Bourne shell
script that formats the nsupdate input somewhat more
efficiently/succinctly than the above code, try
#!/sbin/sh
IPADDR=`/sbin/ifconfig bge1 | sed -n 's/^[ ]*inet \([0-9\.]*\).*$/\1/p'`
cat > /etc/nsupdate << !HERE!DOCUMENT!
server ns4.mydomain.com.
update delete www.mydomain.com. A
update add www.mydomain.com. 86400 IN A $IPADDR
send
!HERE!DOCUMENT!
(There's a tab as well as a space within the square brackets of the
"sed", by the way)
If you have Perl and the necessary modules installed, you could wrap
everything up as follows:
#!/usr/bin/perl
use Net::Interface;
use Net::DNS;
$if = Net::Interface->new ("bge1");
$addr = $if->address;
@octet = unpack("C4", $addr);
$IPADDR = sprintf("%d.%d.%d.%d\n", @octet);
$update = new Net::DNS::Update("mydomain.com");
$update->push(update => rr_del("www.mydomain.com A"));
$update->push(update => rr_add("www.mydomain.com. 86400 A $IPADDR"));
$res = new Net::DNS::Resolver;
$res->nameservers("ns4.mydomain.com");
$reply = $res->send($update);
$reply || die ("Update failed: " . $res->errorstring);
if ($reply->header->rcode eq "NOERROR") {
print "Update successful\n";
} else {
print "Update error code: " . $reply->header->rcode . "\n";
}
Improvements might include
a) more rigorous error checking
b) adding Prerequisites to the Dynamic Update
c) TSIG-signing the Dynamic Update for security
- Kevin
More information about the bind-users
mailing list