[Pdns-users] Performing recursive lookup within Lua

David Coulson david at davidcoulson.net
Sun Mar 6 16:09:55 UTC 2016

I have a pretty simple use case - I'm are doing 1:1 NAT for a /16 and need to manipulate A and PTR records to make sure DNS aligns with NAT.

Modifying A records was easy with Lua & powerdns recursor, however PTR is causing some issues.

I’m using this code:

        if (dq.qtype ==pdns.PTR and endswith(dq.qname:toString(),".232.10.in-addr.arpa."))
                print("PTR mapping for "..dq.qname:toString())
                local newptr=string.gsub(dq.qname:toString(), ".232.10.i", ".51.10.i")
                dq:addAnswer(pdns.CNAME, newptr)
                dq.rcode = 0
                dq:addAnswer(pdns.TXT, "\"Source PTR "..newptr.."\"", 3600)

                return true;

So basically if we do a DNS lookup for 10.232.x.y it returns the PTR for 10.51.x.y - Simple right?

The issue is that powerdns returns both the CNAME and the PTR, so our upstream DNS server ends up with y.x.15.10.in-addr.arpa in it’s cache which conflicts with other 10.51/16 records (which is why we're doing NAT in the first place).

;; ANSWER SECTION: 3590	IN	CNAME 1190	IN	PTR	server.domain.com. 3590	IN	TXT	"Source PTR"

Is there an easy way to get PowerDNS to just return the PTR record, or can I do a query for the 10.51.x.y PTR inside Lua and just respond with that record?

If there is a better way to accomplish what I’m intending, I’m open to suggestions!


More information about the Pdns-users mailing list