How to update DNS record

A

Andi Clemens

Hi,

I want to update our DNS servers periodically with some IP addresses. But I
don't know how to do this.
I searched the Internet quite a while but I haven't found a good example how
to do this.
I want to change the A-Record for some IPs, this shouldn't be too hard.
I looked at dnspython and twisted, but I really don't have a clue how to do
this.
Has anyone done this before?

Andi
 
B

Bjoern Schliessmann

Andi said:
I want to change the A-Record for some IPs, this shouldn't be too
hard. I looked at dnspython and twisted, but I really don't have a
clue how to do this.
Has anyone done this before?

Read RFC 2136 (Dynamic updates in the DNS) and see if your server
can be configured to do this. If not, you'll have to change the
zone files manually and reload the DNS config.

Regards,


Björn
 
A

andi.clemens

Read RFC 2136 (Dynamic updates in the DNS) and see if your server
can be configured to do this. If not, you'll have to change the
zone files manually and reload the DNS config.

It worked before with a perl script, but now I'm using django for all
our web services so I want to implement this update function in Python
as well.
I don't know how to do this in Python, right now I'm trying it with
twisted, but I don't what to do exactly. It would be nice if somebody
has an example for doing this.

Andi
 
B

Bjoern Schliessmann

It worked before with a perl script, but now I'm using django for
all our web services so I want to implement this update function
in Python as well.
I don't know how to do this in Python, right now I'm trying it
with twisted, but I don't what to do exactly. It would be nice if
somebody has an example for doing this.

No one here knows how the server is configured or how the perl
script did it before, so there's little chance someone will have an
example that works for you.

Regards,


Björn
 
A

andi.clemens

Hi,
I'm just a trainee working here and I don't really know how the old
Perl script worked.
But I can post the function, maybe you can recognize what is going on
there:

my $domain = "wiv-dom.com";
my $nameserver = "bldc01.wiv-dom.com";

sub makeDNSEntry {
my $res = new Net::DNS::Resolver;
my $query = $res->query("$domain", "NS");
if ($query) {
print "\nMaking entries into nameserver...\nSearching for
nameservers...\n\n" if $opt{d};
foreach my $rr ($query->answer) {
next unless $rr->type eq "NS";
print $rr->nsdname, "\n" if $opt{d};
}
}
else {
print "query for Nameserver for $domain failed: ", $res-
errorstring, "\n";
}
my $update = new Net::DNS::Update("$domain");
$update->push("pre", yxrrset("$snmpHostName.$domain. A"));
$update->push("update", rr_del("$snmpHostName.$domain. A"));
$update->push("update", rr_add("$snmpHostName.$domain. 3600 A
$outbound"));
$res = new Net::DNS::Resolver;

$res->nameservers("$nameserver");
print "\nNameserver for $domain :" . $nameserver, "\n" if $opt{d};
my $reply = $res->send($update);

if (defined $reply) {
if ($reply->header->rcode eq "NOERROR") {
print "Update for $snmpHostName.$domain. OK\n" if $opt{d};
} else {
print "Update for $snmpHostName.$domain. ERROR : ". $reply-
header->rcode. "\n" if $opt{d};
}
} else {
print "RESERROR : No reply: ". $res->errorstring. "\n";
}
}

What I want to do is change the A-Record of existing entries in the
DNS server.

I'm getting all the IPs from a django database and ask them via SNMP
what their outbound address is, then I want to change those settings
in our DNS server like in the perl script above.

Sorry for my bad explanation, but I never worked with DNS before...

Andi
 
M

Martin P. Hellwig

Andi said:
Hi,

I want to update our DNS servers periodically with some IP addresses. But I
don't know how to do this.
I searched the Internet quite a while but I haven't found a good example how
to do this.
I want to change the A-Record for some IPs, this shouldn't be too hard.
I looked at dnspython and twisted, but I really don't have a clue how to do
this.
Has anyone done this before?

Andi

I'll looked at the perl function you mentioned and it seems to me (but
I'm not a pearl coder) that it uses the dynamic update procedure, which
is explained by the RFC 2136 (Bjoern mentioned that already).

So I googled for "Python DNS dynamic update" and in the results the
following site looked promising, http://www.dnspython.org/.

hth
 
A

Andi Clemens

Martin said:
I'll looked at the perl function you mentioned and it seems to me (but
I'm not a pearl coder) that it uses the dynamic update procedure, which
is explained by the RFC 2136 (Bjoern mentioned that already).

So I googled for "Python DNS dynamic update" and in the results the
following site looked promising, http://www.dnspython.org/.

hth


It's working!!!
Yeah!
I don't know why I didn't get this the first time I tried dnspython, but now
its working! And it's so easy, 3 lines of code:

def make_dns_entry(pix):
update = dns.update.Update(_DOMAIN)
update.replace(pix.name, 3600, 'a', pix.outbound)
response = dns.query.tcp(update, _NAMESERVER)

Thank you for all your help!

Andi
 
B

Bjoern Schliessmann

Andi said:
It's working!!!
Yeah!
I don't know why I didn't get this the first time I tried
dnspython, but now its working! And it's so easy, 3 lines of code:

Great, thanks for reporting back.

Regards,


Björn
 
M

Martin P. Hellwig

Andi Clemens wrote:
It's working!!!
Yeah!
I don't know why I didn't get this the first time I tried dnspython, but now
its working! And it's so easy, 3 lines of code:

def make_dns_entry(pix):
update = dns.update.Update(_DOMAIN)
update.replace(pix.name, 3600, 'a', pix.outbound)
response = dns.query.tcp(update, _NAMESERVER)

Thank you for all your help!

Andi

Glad to be of service!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top