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
Your arguments to Update.delete()
are wrong - the second argument should be an Rdataset
, Rdata
, or rdtype (either Rdatatype
or a string).
Since you pass a string as the second argument, it's treated as an rdtype - so, you should pass the 'A'
as the second argument. If you pass more arguments after the rdtype, passing the IP should work, but I'm not 100% sure what else is allowed; I'm guessing passing the TTL won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With