#!/usr/bin/perl # # Simple script to update entries in DNS based on the premise that # the DNS server you are targeting allows entries to be updated dynamically. # # Jon Hart use diagnostics; use Net::DNS; $SERVER=$ARGV[0] or &usage; $DOMAIN=$ARGV[1] or &usage; $RECORD=$ARGV[2] or &usage; $ENTRY=$ARGV[3] or &usage; my $res = Net::DNS::Resolver->new; $res->nameservers($SERVER); $packet = Net::DNS::Update->new($DOMAIN); $packet->push(update => rr_add("$RECORD $ENTRY")); my $reply = $res->send($packet); if ($reply) { if ($reply->header->rcode eq 'NOERROR') { print "Update succeeded\n"; } else { print "Update failed: ", $reply->header->rcode, "\n"; } } else { print "Update failed: ", $res->errorstring, "\n"; } sub usage { print< Examples: # add forward DNS (A record) $0 10.0.0.1 yourdomain.com test "60 A 10.0.0.5" # add reverse DNS (PTR record), untested $0 10.0.0.1 yourdomain.com 10.0.0.5 "60 PTR test" EOF exit(1); }