2026年5月19日
2026年5月19日
PowerDNSのインストールと設定方法(Ubuntu 24.04・Authoritative Server・Recursor)
PowerDNS は、オープンソースの DNS サーバーです。役割の違う2つのプログラムに分かれています。
| プログラム | パッケージ名 | 役割 |
|---|---|---|
| PowerDNS Authoritative Server | pdns-server |
自分が管理するゾーン(ドメイン)の答えを返す権威サーバー。レコードは SQLite・MySQL・PostgreSQL などのデータベースや BIND 形式のファイルに置く |
| PowerDNS Recursor | pdns-recursor |
利用者の問い合わせを受けて、インターネット上の DNS を順にたどって答えを探すキャッシュサーバー |
この記事では Ubuntu 24.04 に両方を入れ、次の構成を作ります。
- Authoritative Server:
127.0.0.1の 5300 番で待ち受け、内部用のゾーンcorp.internalを SQLite に置く - Recursor: 53 番で待ち受け、
corp.internalの問い合わせだけを Authoritative Server に転送し、それ以外はインターネットに問い合わせる
.internal は、ICANN が内部ネットワーク用に予約したトップレベルドメインです。手順は Authoritative Server 5.1.5 と Recursor 5.4.9 で動作を確認しています(2026年10月時点)。インターネットに公開するドメインの権威サーバーにする場合の違いは、後の節で説明します。
インストールする
Ubuntu 24.04 の標準リポジトリにも pdns-server はありますが、版は 4.8 系です(2026年10月時点)。PowerDNS は公式リポジトリ(repo.powerdns.com)の新しい版を使うことを勧めています。ここでは公式リポジトリから、Authoritative Server の 5.1 系と Recursor の 5.4 系を入れます。系列の番号は repo.powerdns.com で最新の安定版を確かめて読み替えてください。
# 署名鍵を置く
sudo install -d /etc/apt/keyrings
curl -fsSL https://repo.powerdns.com/FD380FBB-pub.asc | sudo tee /etc/apt/keyrings/powerdns-pub.asc >/dev/null
# リポジトリを登録する(auth-51 = Authoritative 5.1 系、rec-54 = Recursor 5.4 系)
echo "deb [signed-by=/etc/apt/keyrings/powerdns-pub.asc] http://repo.powerdns.com/ubuntu noble-auth-51 main" | sudo tee /etc/apt/sources.list.d/pdns-auth.list
echo "deb [signed-by=/etc/apt/keyrings/powerdns-pub.asc] http://repo.powerdns.com/ubuntu noble-rec-54 main" | sudo tee /etc/apt/sources.list.d/pdns-rec.list
# Ubuntu 標準のパッケージより公式リポジトリを優先する
printf 'Package: pdns-*\nPin: origin repo.powerdns.com\nPin-Priority: 600\n' | sudo tee /etc/apt/preferences.d/pdns
sudo apt update
sudo apt install pdns-server pdns-backend-sqlite3 sqlite3 pdns-recursor
入った版は次のように確かめます。apt-cache policy で、公式リポジトリ(repo.powerdns.com)の版が選ばれていることも確認できます。
pdns_server --version 2>&1 | grep 'PowerDNS Authoritative'
pdns_recursor --version 2>&1 | grep 'PowerDNS Recursor'
apt-cache policy pdns-server pdns-recursor
Ubuntu では systemd-resolved が 127.0.0.53 の 53 番を使っています。PowerDNS が待ち受けるアドレスとぶつからないよう、この記事では待ち受けアドレスを明示します。53 番を使っているプログラムは sudo ss -lunpt 'sport = :53' で確かめられます。
Authoritative Server を設定する
設定ファイルの場所
設定は /etc/powerdns/pdns.conf と、そこから読み込まれる /etc/powerdns/pdns.d/ の下のファイルです。インストール直後の pdns.conf は include-dir=/etc/powerdns/pdns.d と launch= だけが有効で、pdns.d/bind.conf に BIND 形式のファイルを使う設定が入っています。今回は SQLite を使うので、bind.conf を外します。
sudo mv /etc/powerdns/pdns.d/bind.conf /etc/powerdns/bind.conf.disabled
SQLite のデータベースを作る
テーブルの定義(スキーマ)は pdns-backend-sqlite3 パッケージに入っています。
sudo mkdir -p /var/lib/powerdns
sudo sqlite3 /var/lib/powerdns/pdns.sqlite3 < /usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql
sudo chown -R pdns:pdns /var/lib/powerdns
SQLite はデータベースファイルのあるディレクトリにも書き込むため、ディレクトリごと PowerDNS の実行ユーザー pdns の持ち物にします。
設定を書く
/etc/powerdns/pdns.d/local.conf を作ります。
# バックエンド(SQLite)
launch=gsqlite3
gsqlite3-database=/var/lib/powerdns/pdns.sqlite3
# 待ち受け(Recursor と同じサーバーなので 127.0.0.1 の 5300 番)
local-address=127.0.0.1
local-port=5300
# ゾーン作成時の SOA の既定値(@ はゾーン名に置き換わる)
default-soa-content=ns1.@ hostmaster.@ 0 10800 3600 604800 3600
default-soa-content を書かないと、ゾーンを作ったときの SOA のプライマリーサーバー名が a.misconfigured.dns.server.invalid になります。設定したら再起動して、状態を確かめます。
sudo systemctl restart pdns
systemctl status pdns
ゾーンを作る前に問い合わせると、自分が管理していない名前なので REFUSED が返ります。これは正常です。
dig @127.0.0.1 -p 5300 test.corp.internal A +norec | grep status
ゾーンとレコードを登録する
pdnsutil で登録します。PowerDNS 5.0 から pdnsutil のコマンドの書き方が変わり、pdnsutil zone create や pdnsutil rrset add の形になりました(5.1 では従来の create-zone などの書き方も受け付けます)。SQLite に書き込むため、pdns ユーザーで実行します。
# ゾーンを作る(NS レコードも1つ作られる)
sudo -u pdns pdnsutil zone create corp.internal ns1.corp.internal
# レコードを足す(名前 種類 TTL 値)
sudo -u pdns pdnsutil rrset add corp.internal ns1.corp.internal A 3600 192.0.2.53
sudo -u pdns pdnsutil rrset add corp.internal www.corp.internal A 300 192.0.2.10
sudo -u pdns pdnsutil rrset add corp.internal corp.internal MX 3600 '10 mail.corp.internal'
# 誤りがないか調べ、内容を表示する
sudo -u pdns pdnsutil zone check corp.internal
sudo -u pdns pdnsutil zone list corp.internal
Ubuntu 標準の 4.8 系を使う場合は、pdnsutil create-zone corp.internal ns1.corp.internal、pdnsutil add-record corp.internal www A 300 192.0.2.10、pdnsutil check-zone、pdnsutil list-zone の書き方になります。
動いている Authoritative Server に新しいゾーンを知らせるため、ゾーンの一覧を読み直させます。
sudo pdns_control rediscover
問い合わせて確かめます。flags に aa(権威のある応答)が付いていれば、Authoritative Server が自分のゾーンとして答えています。
dig @127.0.0.1 -p 5300 www.corp.internal A +norec +short
dig @127.0.0.1 -p 5300 www.corp.internal A +norec | grep flags
直前に同じ名前を問い合わせていると、REFUSED などの古い応答がキャッシュから返ることがあります。その場合は少し待ってから問い合わせ直します。
Recursor を設定する
Recursor 5.x の設定ファイルは YAML 形式です。5.2 以降は YAML が既定で、従来の キー=値 形式は --enable-old-settings を付けたときだけ読まれます。公式リポジトリのパッケージでは、/etc/powerdns/recursor.conf に YAML 形式の設定が入っています。これを次のように書き換えます。
dnssec:
trustanchorfile: /usr/share/dns/root.key
# DNSSEC 署名のない内部ゾーンを検証の対象から外す
negative_trustanchors:
- name: corp.internal
reason: internal zone without DNSSEC
recursor:
hint_file: /usr/share/dns/root.hints
include_dir: /etc/powerdns/recursor.d
# corp.internal だけを Authoritative Server に転送する
forward_zones:
- zone: corp.internal
forwarders:
- 127.0.0.1:5300
incoming:
# 待ち受けるアドレスと、問い合わせを受け付ける送信元
listen:
- 127.0.0.1
allow_from:
- 127.0.0.0/8
outgoing:
sudo systemctl restart pdns-recursor
systemctl status pdns-recursor
dig @127.0.0.1 www.corp.internal A +short
dig @127.0.0.1 wordpress.org A +short
1つ目で 192.0.2.10、2つ目で wordpress.org のアドレスが返れば、内部ゾーンの転送とインターネットへの問い合わせの両方が動いています。
設定の要点です。
- negative_trustanchors: Recursor は既定で DNSSEC の検証を行います。署名のない内部ゾーンを転送すると、検証に失敗した(Bogus)と判定されて
SERVFAILが返ることがあります(確認した環境では、この行がないとwww.corp.internalがSERVFAILになりました)。内部ゾーンはここに書いて検証から外します。 - listen と allow_from: 社内の他の PC からも使わせる場合は、
listenにサーバーの LAN 側のアドレス(例:192.168.1.10)を足し、allow_fromにその LAN の範囲(例:192.168.1.0/24)を足します。allow_fromをインターネット全体に広げると、だれでも使えるリゾルバー(オープンリゾルバー)になり、DNS を使った攻撃の踏み台にされるおそれがあります。 - 従来形式の設定を持っている場合は、
rec_control show-yamlで YAML に変換した内容を表示できます。
API を有効にする(任意)
Authoritative Server は HTTP の API でゾーンやレコードを操作できます。管理画面や外部のツールから使う場合は、/etc/powerdns/pdns.d/local.conf に足します。
api=yes
api-key=長いランダムな文字列に置き換える
webserver=yes
webserver-address=127.0.0.1
webserver-port=8081
webserver-allow-from=127.0.0.1
sudo systemctl restart pdns
curl -s -H 'X-API-Key: 設定した文字列' http://127.0.0.1:8081/api/v1/servers/localhost/zones
API はゾーンの書き換えができるため、webserver-address と webserver-allow-from は管理に使うアドレスに限り、インターネットに公開しないでください。キーは openssl rand -base64 32 などで作れます。
公開ドメインの権威サーバーにする場合
インターネットに公開するドメイン(例: example.com)の権威サーバーにする場合は、主に次の点が変わります。
local-addressをサーバーのグローバル IP アドレスにし、local-portは既定の 53 番にする(local-portの行を消す)- ファイアウォールで 53 番の UDP と TCP を開ける
- ゾーン名を自分のドメインにし、
default-soa-contentのプライマリーサーバー名と管理者アドレスを実在のものにする - ドメインを登録しているレジストラで、ネームサーバーをこのサーバーの名前に変える。ネームサーバー名が同じドメインの中にある場合(例:
ns1.example.com)は、グルーレコードの登録も必要 - 1台が止まると名前解決ができなくなるため、2台以上の権威サーバーで運用する
Recursor は公開ドメインの権威サーバーには不要です。権威サーバーとキャッシュサーバーを同じアドレスで外に公開するのは避けてください。
まとめ
- PowerDNS は権威サーバー(
pdns-server)とキャッシュサーバー(pdns-recursor)が別のプログラム - Ubuntu 24.04 では公式リポジトリ(repo.powerdns.com)から入れ、
Pin-Priorityで優先させる - Authoritative Server は
pdns.d/bind.confを外し、launch=gsqlite3と SQLite のスキーマで動かす。ゾーンは 5.x ではpdnsutil zone create・pdnsutil rrset addで作り、pdns_control rediscoverで読み直させる - Recursor 5.x の設定は YAML。内部ゾーンは
forward_zonesで転送し、negative_trustanchorsで DNSSEC の検証から外す allow_fromと API の待ち受けアドレスは必要な範囲に限る