Setting up DNS server on Raspberry Pi with PowerDNS

Installing PowerDNS

apt-get install pdns-server

Configuring a recursor

Before we start setting up our zone file we need to configure our recursor. The recursor is the DNS server that will handle queries which our DNS server doesn’t have zone configurations for (,, etc.). So in the next command we’re going to use sed to set the recursor in /etc/powerdns/pdns.conf to Google’s Public DNS ( but preferably to your ISP DNS.

sed -i 's/# recursor=/recursor=' /etc/powerdns/pdns.conf
sed -i 's/allow-recursion=,\/24/g' /etc/powerdns/pdns.conf

Now restart the pdns service and also install dnsutils so we can test it.

service pdns restart
apt-get install dnsutils

To confirm that recursion against our DNS server we’ll execute the following query for against it.

nslookup localhost

If you get a list of names and addresses back then everything is configured and working properly:

Configuring a zone

So now we’ll move onto configuring our own zone. You can think of a zone as basically your domain name ( PowerDNS uses /etc/powerdns/bindbackend.conf as it’s main configuration file for Bind9. So let’s open that up and we’ll create a zone like the following.

zone "" {
        type master;
        file "/etc/powerdns/bind/";
        allow-update { none; };

You’ll want to replace with whatever you want your domain to be. Now you’ll notice we made a reference to a file called /etc/powerdns/bind/, this is where our DNS records forĀ will go. First we’ll create the /etc/powerdns/bind folder.

mkdir /etc/powerdns/bind

Next let’s go ahead and create /etc/powerdns/bind/ with the following.

$ORIGIN     ; base for unqualified names
$TTL 1h                 ; default time-to-live
@                       IN      SOA (
                                1; serial
                                1d; refresh
                                2h; retry
                                4w; expire
                                1h; minimum time-to-live
                        IN      NS      ns
                        IN      A
ns                      IN      A

In this zone file we’ve setup a couple of basic things. The first record is the SOA (Start Of Authority) record. This tells the DNS server what the primary data source is for the zone and how it should propagate. After that we setup an NS (nameserver) record. The job of this record is to point to our authoritative DNS server for the zone, which happens to be this server. We then have an A record for the zone itself so that -> And then after that I have another A record so that ->

Now if we restart PowerDNS and use nslookup we can verify that it’s working correctly.

service pdns restart
nslookup localhost

A successful response should return the IP that you mapped to.

Adding a new record

The basic zone and the DNS server are all setup at this point so in order to add a new record we can append a line like this to the zone file.

webserver               IN      A

Most of the time there are two types of records you’ll be adding. As we’ve already seen an A record always maps to an IP. A CNAME record is used when want to map an alias to another record. For example look at the following.

webserver               IN      A
www                     IN      CNAME   webserver

What I’ve done there is map -> and then mapped -> It’s essential to learn to use CNAME records effectively because if the IP for had changed and I had used two A records then I’d have to update both records. However, using an A and a CNAME I’d only have to update the IP for

After you’re done adding your records just restart the pdns service to bring in the changes.

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × 5 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.