Consider this scenario: With nsupdate I'm able to remove IP from a A record using following method:
update delete test-record.mydomain.com 60 A 172.16.1.4
This is my naive implementation with dnspython, where bind_host is our bind server, domain_name is "mydomain.com." and sub_domain is "test-record" and ip is "172.16.1.4".
def delete_dns_record(self, bind_host, domain_name, sub_domain, ip):
update = dns.update.Update(domain_name)
update.delete(sub_domain, '60', 'A', ip)
response = dns.query.tcp(update, bind_host, timeout=10)
return response
Running function will throw following error:
Traceback (most recent call last):
File "dns_magic/check.py", line 136, in <module>
dnstest()
File "dns_magic/check.py", line 134, in dnstest
print(hc.delete_dns_record('1.2.3.4', 'mydomain.com.', 'test-record', '172.16.1.4' ))
File "dns_magic/check.py", line 106, in delete_dns_record
update.delete(sub_domain, '60', 'A', ip)
File "dns_magic/lib/python3.6/site-packages/dns/update.py", line 160, in delete
rdtype = dns.rdatatype.from_text(rdtype)
File "dns_magic/lib/python3.6/site-packages/dns/rdatatype.py", line 214, in from_text
raise UnknownRdatatype
dns.rdatatype.UnknownRdatatype: DNS resource record type is unknown.
Any ideas how to continue? I'm also open for alternative methods with Python.
UPDATE Working solution:
def delete_dns_record(bind_host, domain_name, sub_domain, ip):
update = dns.update.Update(domain_name)
update.delete(sub_domain, dns.rdatatype.A, ip)
response = dns.query.tcp(update, bind_host, timeout=10)
return response