How to add zone to bind using dnspython

766 views
Skip to first unread message

David Okwii

unread,
Aug 23, 2016, 5:47:08 AM8/23/16
to dnspython-users
Hello, I've been struggling with this issue and I don't see it addressed in the documentation. 

I want to add a domain to by bind configuration. I know that you have to add a zone in named.conf and then add the zone file with actual dns records. 

I see that dnspython has addressed how to create and add dns records to a zone file as I can demonstrate in the following code; 

import dns.rdataset
import dns.zone

zone = dns.zone.Zone(dns.name.from_text('example.com')) 
zone['@'] = dns.rdataset.from_text('IN', 'NS', 3600, 'ns1.example.com')
zone.to_file("/etc/bind/master/example.com.zone")

However, before a zone file is added, one must define a zone under /etc/bind/named.conf such as; 
zone "example.com" IN {
        type master;
        file "/etc/bind/master/example.com";
        allow-update { key rndc-key; };
};

So does dnspython have a way of defining a zone in named.conf? Or is this something I've to manually add in other ways? Thanks. 

Anand Buddhdev

unread,
Aug 23, 2016, 6:02:32 AM8/23/16
to David Okwii, dnspython-users
On 23/08/16 11:47, David Okwii wrote:

Hi David,

[snip]

> So does dnspython have a way of defining a zone in named.conf? Or is this
> something I've to manually add in other ways? Thanks.

dnspython doesn't know how to manage bind's named.conf file. That's not
within the scope of dnspython's feature set.

You'll have to add zones to named.conf by hand, or write other python
code to do that. For example, with recent versions of bind, you can
dynamically add zones with something like this:

rndc addzone ...

So you can also get your python code to call "rndc" with the appropriate
parameters. Please read the bind documentation for more details about
this. Alternatively, you can get your code to edit named.conf, and then
call "rndc reconfig" to pick up the new zone. Be sure that your code to
edit named.conf is robust.

Regards,
Anand

David Okwii

unread,
Aug 23, 2016, 7:55:15 AM8/23/16
to dnspython-users

On Tue, Aug 23, 2016 at 1:02 PM, Anand Buddhdev <ana...@ripe.net> wrote:
Anand

Thanks Anand, 

That clarifies a lot of things. I think I'll go with rndc for adding and deleting zones and as you have stated write python code to call the command. 


--
Thanks & regards,
David Okwii,
Mobile(default): +256-791-040-262

Christ in me the Hope of Glory(Col.1:27)
Reply all
Reply to author
Forward
0 new messages