Skip to content


Repository files navigation

PowerDNS 4.x API bindings for Golang

This community project provides bindings for PowerDNS Authoritative Server. It's not associated with the official PowerDNS product itself.

Test coverage Go Report Card PkgGoDev


  • Zone handling
  • Resource record handling
  • Server statistics gathering
  • DNSSEC handling

For more features, consult our documentation.


go get -u
import ""


Initialize the handle

import (

pdns := powerdns.NewClient("http://localhost:80", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)

Assuming that the server is listening on http://localhost:80 for virtual host localhost, the API password is apipw and you want to edit the domain

Get/add/change/delete zones

ctx := context.Background()

zones, err := pdns.Zones.List(ctx)
zone, err := pdns.Zones.Get(ctx, "")
export, err := pdns.Zones.Export(ctx, "")
zone, err := pdns.Zones.AddNative(ctx, "", true, "", false, "foo", "foo", true, []string{""})
err := pdns.Zones.Change(ctx, "", &zone)
err := pdns.Zones.Delete(ctx, "")

Add/change/delete resource records

err := pdns.Records.Add(ctx, "", "", powerdns.RRTypeAAAA, 60, []string{"::1"})
err := pdns.Records.Change(ctx, "", "", powerdns.RRTypeAAAA, 3600, []string{"::1"})
err := pdns.Records.Delete(ctx, "", "", powerdns.RRTypeA)
records, err := pdns.Records.Get(ctx, "", "", powerdns.RRTypePtr(powerdns.RRTypeA))

Request server information and statistics

statistics, err := pdns.Statistics.List(ctx)
servers, err := pdns.Servers.List(ctx)
server, err := pdns.Servers.Get(ctx, "localhost")

Handle DNSSEC cryptographic material

cryptokeys, err := pdns.Cryptokeys.List(ctx)
cryptokey, err := pdns.Cryptokeys.Get(ctx, "", "1337")
err := pdns.Cryptokeys.Delete(ctx, "", "1337")

Create/change/delete tsigkeys

tsigkey, err := pdns.TSIGKey.Create(ctx, "examplekey", "hmac-sha256", "")
tsigkey, err := pdns.TSIGKey.Change(ctx, "examplekey.", powerdns.TSIGKey{
	Key: powerdns.String("newkey"),
tsigkeys, err := pdns.TSIGKey.List(ctx)
tsigkey, err := pdns.TSIGKey.Get(ctx, "examplekey.")
err := pdns.TSIGKey.Delete(ctx, "examplekey.")

More examples

There are several examples on


See for a full reference.



Tested PowerDNS versions

Supported versions of PowerDNS Authoritative Server ("API v1"):

  • 4.6
  • 4.7
  • 4.8

Version 4.1, 4.2 and 4.3 are probably working fine, but are officially end-of-life. Be aware that there are breaking changes in "API v1" between PowerDNS 3.x, 4.0 and 4.1.

Tested Go versions

In accordance with Go's version support policy, this module is being tested with the following Go releases:

  • 1.21
  • 1.22


This API client has not been completed yet, so feel free to contribute. The OpenAPI specification is a good reference.

You can use Docker Compose to launch a PowerDNS authoritative server including a generic SQLite3 backend, DNSSEC support and some optional fixtures:

docker-compose -f docker-compose-v4.8.yml up
docker-compose -f docker-compose-v4.8.yml exec powerdns sh

It's also possible to target mocks against this server, or any other PowerDNS instance which is running on http://localhost:8080.

make test-without-mocks

The mocks assume there is a vHost/Server ID called localhost and API key apipw.