Using the pipe backend in PowerDNS

PowerDNS is a Domain Name System (DNS) server with a lot of different possible backends, such as MySQL, PostgreSQL, LDAP, BIND zone files and a Unix pipe backend. In this article we will look at the pipe backend which is passed the DNS request by PowerDNS through standard input (stdin) and must reply through standard output (stdout).

We will first install PowerDNS and the pipe backend on CentOS:

yum install pdns pdns-backend-pipe

Then we can edit the PowerDNS configuration file /etc/pdns/pdns.conf

query-cache-ttl=0
cache-ttl=0
loglevel=7
log-dns-details=no
wildcards=no
launch=pipe
pipe-command=/root/pdns-backend.py

And the pipe backend file /root/pdns-backend.py

#!/usr/bin/python

from sys import stdin, stdout

data = stdin.readline()
stdout.write("OKtMy Backendn")
stdout.flush()

while True:
    data = stdin.readline().strip()
    kind, qname, qclass, qtype, id, ip = data.split("t")
    stdout.write("DATAt" + qname + "t" + qclass + "tAt3600t" + id + "t1.2.3.4n")
    stdout.write("LOGt" + data + "n")
    stdout.write("ENDn")
    stdout.flush()

This example pipe backend will always return the IP address 1.2.3.4 regardless of the hostname that was sent in the query, as you can see from the following query:

# nslookup www.example.com 127.0.0.1
Server:  127.0.0.1
Address: 127.0.0.1#53

Name:    www.example.com
Address: 1.2.3.4

This is of course a very silly way to respond, but you can always change this behaviour by looking at the actual query parameters. In the example given above, these parameters are as follows:

kind   = Q
qname  = www.example.com
qclass = IN
qtype  = ANY
id     = -1
ip     = 127.0.0.1

Please also note that the current response is always an A record, even if the response should be something else, e.g. a PTR or MX record.

Leave a Reply

Your email will not be published. Name and Email fields are required.