Reputation: 61
I try to add DNS record by using DNSPython;
it works well when I set dns like this:
import dns.resolver
import dns.query
import dns.reversename
import dns.update
import dns.rdatatype
update = dns.update.Update('test.com')
update.replace('a', 3600, dns.rdatatype.A, '10.10.10.10')
response = dns.query.tcp(update, '127.0.0.1')
However it doesn't work when I set reverse dns by the same way:
update = dns.update.Update('10.in-addr.arpa')
update.replace('10.10.10.', 3600, dns.rdatatype.PTR, 'a.test.com')
response = dns.query.tcp(update, '127.0.0.1')
I want to know how to set reverse dns successfully, Thx~
Upvotes: 1
Views: 1974
Reputation: 174
Encountered this issue myself.
You're missing a dot at the end of you name:
update.replace('10.10.10', 3600, dns.rdatatype.PTR, 'a.test.com**.**')
Upvotes: 1
Reputation: 331
You have issue with the '10.10.10' in the update.replace. It needs to be FQDN - '10.10.10.10.in-addr.arpa'. You can use something like this:
Get reverse IP
reventry = dns.reversename.from_address('10.10.10.10')
Define in-addr.arpa zone to update - I have .labels[3:] for A class subnet zone file (10.in-addr.arpa). If you have C class (10.10.10.in-addr.arpa) then use .labels[1:]
revzone = ''
revzone = '.'.join(dns.name.from_text(str(reventry)).labels[3:])
And add the action
raction = dns.update.Update(revzone)
raction.replace(reventry, 3600, dns.rdatatype.PTR, 'a.test.com')
This should work just fine.
Upvotes: -1
Reputation: 61
I find the problem:
update.replace('10.10.10.', 3600, dns.rdatatype.PTR, 'a.test.com')
this should be like this;
update.replace('10.10.10', 3600, dns.rdatatype.PTR, 'a.test.com')
But another problem is: This way to update reverse dns is not always successful, sometimes when I use 'nslookup' to test, it seems that it isn't added to dns server;
what's more, when I nslookup ip like:
nslookup 10.10.10.10
Server: 127.0.0.1
Address: 127.0.0.1#53
10.10.10.10.in-addr.arpa name =a.test.com.10.in-addr.arpa.
This is not what I want, when using nsupdate to add, it only shows:
10.10.10.10.in-addr.arpa name =a.test.com.
What can I do to fix this?
Upvotes: 1