DNSサーバ

BINDでrndcコマンドが利用できない

DNSサーバ機能を提供するbind (isc-bind) をFreeBSDで単純にインストールするとrndcコマンドでコントロールすることができません。ここでは、portsインストールされたbind9 で、rndcコマンド管理を行うための設定手順を紹介します。

rndcコマンドとは?


rndc コマンド自体知らない人がいるかもしれません。 Remote Name server Daemon Controlの略称で、bind8までに利用されていたndcコマンドを拡張し、遠隔ホストで稼働しているbind9までもコントロールできるコマンドです。
実行内容
コマンド引数
DNSサーバ停止 # rndc stop
DNSサーバ開始 # rndc start
状態表示 # rndc status
緊急停止 # rndc halt
ゾーンファイル再読み込み # rndc reload
特定ゾーンファイル読み込み # rndc reload ZONENAME
デバッグレベル変更 # rndc trace
データベースリフレッシュ(キャッシュ等消去) # rndc refresh
クエリログ表示 # rndc querylog
引数なしで実行すると利用可能なコマンドが表示されます。

rndcコマンドが失敗する


FreeBSDで、portsコレクションからbind9をインストールした直後の環境では以下のようなメッセージが表示されてrndcコマンドが利用できない場合があります。
# rndc reload
rndc: connection to remote host closed
This may indicate that the remote server is using an older version of
the command protocol, this host is not authorized to connect,
or the key is invalid.
これは、rndcコマンドを利用するためのセキュリティー設定である、keyファイルが適切に生成されていないために発生しています。必要な設定は以下の通り。

  1. rndc.confファイルの作成
    rndc-confgenコマンドを発行し、rndc.confファイル、named.confファイルのサンプルを取得します。引数については各自確認してください。
    # rndc-confgen -b 512 -k rndc.key
    # Start of rndc.conf
    key "rndc.key" {
    algorithm hmac-md5;
    secret "E5JFWzTa+9KAmK62ndpzuoRqyA9pfJUSCLaTWstboUDinYw2DXuHpLy1HGj5tQgRiMWCf4Lr0wij6XTwgSpjNQ==";
    };
    options {
    default-key "rndc.key";
    default-server 127.0.0.1;
    default-port 953;
    };

    # End of rndc.conf
    # Use with the following in named.conf, adjusting the allow list as needed:
    # key "rndc.key" {
    # algorithm hmac-md5;
    # secret "E5JFWzTa+9KAmK62ndpzuoRqyA9pfJUSCLaTWstboUDinYw2DXuHpLy1HGj5tQgRiMWCf4Lr0wij6XTwgSpjNQ==";
    # };
    #
    # controls {
    # inet 127.0.0.1 port 953
    # allow { 127.0.0.1; } keys { "rndc.key"; };

    # };
    # End of named.conf
    # Start of rndc.confから# End of rndc.confの内容を/var/named/etc/namedb/rndc.confとして保存します。
    # vi /var/named/etc/namedb/rndc.conf

  2. named.confファイルの修正
    1.の# Use with the following in named.confから、# End of named.confまでをコメントアウトして、/var/named/etc/namedb/named.confに追記します。
    # vi /var/named/etc/namedb/named.conf

  3. rndc.keyファイルの作成
    # rndc-confgen -a -b 512 -k rndc.key
    wrote key file "/usr/local/etc/rndc.key"
    作成されたキーファイル中のsecret行内容を1.で生成したキーに置き換えます。
    # vi /usr/local/etc/rndc.key

  4. ファイルパーミッションの変更
    作成した、rndc.conf、rndc.keyファイルの所有者を変更します。
    # chown bind:bind /usr/local/etc/rndc.key
    # chown bind:bind /var/named/etc/namedb/rndc.conf

  5. namedサービスの再起動
    # /etc/rc.d/named restart
    Stopping named.
    Starting named.

  6. rndcコマンド動作確認
    # rndc status
    number of zones: 5
    debug level: 0
    xfers running: 0
    xfers deferred: 0
    soa queries in progress: 0
    query logging is OFF
    recursive clients: 0/1000
    tcp clients: 0/100

    server is up and running