0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerDNSで権威サーバを構築する(PowerDNS 5.x)

0
Last updated at Posted at 2026-08-13

概要

自宅ラボ環境を運用していると、名前解決が必要になる。個人的にも、最近はネットワーク開発から仮想化基盤開発側に比重が重くなって来ていることもあり、名前解決の必要性が高まった。 以下で PowerDNS 4.x での構築例を整理していたが、Ubuntu 26.04 では PowerDNS 5.x 系が採用された。5.x系では設定ファイルの書き方やDNSレコードの登録方法なども変更されており、構築方法を改めて整理する。

また、ここで構築する権威サーバを利用した名前解決の仕組みは以下で整理している。合わせて参照のこと。

検証環境

PowerDNSの権威サーバは、バックエンドとして PostgreSQL/MySQL/SQLite3 などのデータベースを利用可能。今回は個人的な趣味で PostgreSQLを使用する。

種別 ソフトウェア バージョン 備考
OS Ubuntu Server 26.04
DNSサーバ PowerDNS 5.0.2-1build1 APTでいれる
DBサーバ PostgreSQL 18.4 APTでいれる

PowerDNSの構築

systemd-resolved との競合回避

Ubuntu サーバ自体も名前解決を必要とする。
IPv4 の Loopback アドレスが 127.0.0.0/8であることを利用し、systemd-resolvedと PowerDNS で利用する Loopback アドレスを調整することで、Portの競合を回避する。

利用プロセス アドレス(例) Port番号(例)
PowerDNS Recursor 192.168.1.53 53
PowerDNS Authoritative 127.0.0.1 5300
systemd-resolved 127.0.0.53 53

PowerDNSのインストール

sudo apt install pdns-server pdns-tools

今回は、同じVMへ後からPowerDNS Recursorを追加することを想定する。クライアントからの名前解決はRecursorが53番で受け、内部ゾーンだけ権威サーバの5300番へ転送する。権威サーバ単独でLANへ公開する構成なら、LANアドレスの53番で待ち受けてもよい。

Databaseの用意(PostgreSQLの場合)

必要なパッケージのインストール

sudo apt install pdns-backend-pgsql postgresql

PostgreSQL ユーザ pdns を作成

shakapon@dns:~$ sudo -u postgres createuser -P -e pdns
Enter password for new role 
Enter it again: 

ここで入力するのは、PowerDNSがPostgreSQLへ接続するために使用するpdnsロールの Password. PostgreSQL管理者であるpostgres の Passwordではない。

オプション 意味
-P 新しいユーザのパスワードプロンプトを表示
-e サーバに送ったコマンドをエコー表示する

よくよく調べると -s オプションは不要だった。権限制御のため削除。
ここで設定した pdnsユーザのパスワードは、後ほど PowerDNSからPostgreSQL(127.0.0.1:5432)へ接続するときに利用する。

Databaseの作成

/usr/share/pdns-backend-pgsql/schema/schema.pgsql.sql にあるスキーマファイルを流し込んで作成する。

sudo -u postgres createdb -O pdns pdns
sudo -u pdns sh -c "psql -U pdns -d pdns -a -f /usr/share/pdns-backend-pgsql/schema/schema.pgsql.sql"

初期設定の変更(pdns.conf)

利用するデータベースを指定する。オプション設定が結構違う。

sudo vi /etc/powerdns/pdns.conf

変更前

#################################
# launch        Which backends to launch and order to query them in
#
# launch=

変更後(PostgreSQLの場合)

#################################
# launch        Which backends to launch and order to query them in
#
launch=gpgsql
gpgsql-host=127.0.0.1
gpgsql-port=5432
gpgsql-dbname=pdns
gpgsql-user=pdns
gpgsql-password="PostgreSQLにログインする際のパスワード"

変更後(systemd-resolved との競合回避)

#################################
# local-address Local IP addresses to which we bind
#
# local-address=0.0.0.0, ::
local-address=127.0.0.1
(snip)
#################################
# local-port    The port on which we listen
#
# local-port=53
local-port=5300

Port の競合を回避するため、local-port をデフォルトの53から5300へ変更。

設定確認

sudo pdns_server --config=checkコマンドで文法エラーをチェックできる。特にErrorがなければOK。

shakapon@dns:~$ sudo pdns_server --config=check
Aug 13 09:46:02 Loading '/usr/lib/x86_64-linux-gnu/pdns/libgpgsqlbackend.so'
Aug 13 09:46:02 Loading '/usr/lib/x86_64-linux-gnu/pdns/libbindbackend.so'

サービス開始

systemctlで起動可能。

sudo systemctl restart pdns
sudo systemctl status pdns

起動確認

起動確認はsystemctl status pdnsで行う。うまくいけばこんな感じ。Active の項目が active (running) になってくれる。

shakapon@dns:~$ systemctl status pdns
● pdns.service - PowerDNS Authoritative Server
     Loaded: loaded (/usr/lib/systemd/system/pdns.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-08-12 16:03:34 UTC; 17h ago
 Invocation: 420685ce72364970a757a724214cf9fc
       Docs: man:pdns_server(1)
             man:pdns_control(1)
             https://doc.powerdns.com
   Main PID: 20864 (pdns_server)
      Tasks: 8 (limit: 3989)
     Memory: 47M (peak: 47.5M)
        CPU: 2.954s
     CGroup: /system.slice/pdns.service
             mq20864 /usr/sbin/pdns_server --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pi>

Portの競合確認

shakapon@dns:~$ sudo ss -luntp | awk 'NR == 1 || /:53/ || /:5300/'
Netid State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
udp   UNCONN 0      0          127.0.0.1:5300      0.0.0.0:*    users:(("pdns_server",pid=20864,fd=5))
udp   UNCONN 0      0         127.0.0.54:53        0.0.0.0:*    users:(("systemd-resolve",pid=627,fd=18))
udp   UNCONN 0      0      127.0.0.53%lo:53        0.0.0.0:*    users:(("systemd-resolve",pid=627,fd=16))
tcp   LISTEN 0      128        127.0.0.1:5300      0.0.0.0:*    users:(("pdns_server",pid=20864,fd=6))
tcp   LISTEN 0      4096   127.0.0.53%lo:53        0.0.0.0:*    users:(("systemd-resolve",pid=627,fd=17))
tcp   LISTEN 0      4096      127.0.0.54:53        0.0.0.0:*    users:(("systemd-resolve",pid=627,fd=19))

systemd-resolvedとpdns_serverで待受アドレスおよびポートが分離され、競合せずに動作していることが確認できる。

正常性確認

PowerDNSのチュートリアル 通り、example.comをネタにレコードを追加。4.x系からコマンドが変わっているのでハマった。

$ sudo pdnsutil zone create example.com ns1.example.com
Creating empty zone 'example.com'
Also adding one NS record
$ sudo pdnsutil rrset add example.com ns1.example.com A 192.0.2.53
ns1.example.com. 3005 IN A 192.0.2.53
$ sudo pdnsutil rrset add example.com example.com MX '25 mail.example.com'
New rrset:
example.com. 3005 IN MX 25 mail.example.com
$ sudo pdnsutil rrset add example.com mail.example.com A 192.0.2.25
mail.example.com. 3005 IN A 192.0.2.25
$ sudo pdnsutil rrset add example.com www.example.com A 192.0.2.1
New rrset:
www.example.com. 3005 IN A 192.0.2.1

digコマンドで返ってくれば成功。

$ dig +short www.example.com @127.0.0.1 -p 5300
192.0.2.1
$ dig +short example.com MX @127.0.0.1 -p 5300
25 mail.example.com.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?