0

Im trying to add a PTR record with dnspython to bind9 using this code:

def send_query(query, server):
    update = dns.query
    update.tcp(query, server)

def add(name, rdtype, rdata, ttl=300, zone):
    server = dns.resolver.Resolver()
    server.nameservers = '<dns server>'
    keyring = dns.tsigkeyring.from_text({
            'key-name': 'key'
    })
    record = dns.update.Update(zone=zone, keyring=keyring)
    record.add(name, ttl, rdtype, rdata)
    send_query(record, server.nameservers)

Im able to successfully add the record when passing:

name = last octet
rdtype = PTR
data = server-FQDN
zone = z.y.x.in-addr.arpa

but when querying the dns server via nslookup I get:

~ nslookup X.Y.Z.6
Server:     NS server
Address:    NS server#53

6.Z.Y.X.in-addr.arpa        name = server-FQDN.Z.Y.X.in-addr.arpa.

The problem is the "Z.Y.X.in-addr.arpa." part added to the query. In the zone file the record is in the right syntax

Is there a better way to add PTR record with dnspython?

Chen Shabi
  • 174
  • 1
  • 9

1 Answers1

2

The reason this didn't work was that I forgot to add the ending "." at the end of the hostname FDQN and therefore the domain was completed automatically.

Chen Shabi
  • 174
  • 1
  • 9