[Memo2010][ITPASS] tako 構築作業ログ 5 (DNS)

ビルドとインストール

$ sudo -s
# cd /usr/local/src

配布サイト <URL:https://www.isc.org/> からアーカイブを取得. 今回のバージョンは bind9.7.2-P2

# wget http://ftp.isc.org/isc/bind9/9.7.2-P2/bind-9.7.2-P2.tar.gz
# tar zxfv bind-9.7.2-P2.tar.gz
# cd bind-9.7.2-P2

# mkdir /usr/local/bind
# ./configure --prefix=/usr/local/bind

Bind をインストールする.

# make
# make install

インストールした Bind には host 等のコマンドも同梱されているため, 既にインストールされている bind9-host, libbind9-0, dnsutils は削除する.

# apt-get remove bind9-host libbind9-0 dnsutils

インストールした実行ファイルへのパスの設定

インストールされた Bind の実行ファイル群へパスを通す. /etc/bash.bashrc の冒頭に以下のように追加した.

# add PATH for local installed softwares
PATH="${PATH}:/usr/local/apache2/bin:/usr/local/bind/bin"
                                    ^^^^^^^^^^^^^^^^^^^^
# add PATH for local installed softwares (for root)
if [ "`id -u`" -eq 0 ]; then
  PATH="${PATH}:/usr/local/apache2/bin:/usr/local/bind/sbin"
fi                                    ^^^^^^^^^^^^^^^^^^^^^

export PATH

インストールしたマニュアルへのパスの設定

/etc/manpath.config に以下の行を追加した.

MANDATORY_MANPATH                          /usr/local/bind/man
MANPATH_MAP        /usr/local/bind/bin     /usr/local/bind/man
MANPATH_MAP        /usr/local/bind/sbin    /usr/local/bind/man
MANDB_MAP          /usr/local/bind/man     /usr/local/bind/man

ユーザとグループ追加

Bind の実行ユーザとして bind ユーザを作成する. vipw を実行して以下の行を追加した.

bind:x:53:53:Bind Sandbox:/usr/local/bind/var:/bin/false

vipw -s を実行して以下の行を追加した.

bind:!:13749:0:99999:7:::

同様に bind グループを追加する. vigr を実行して以下の行を追加した.

bind:x:53:

vigr -s を実行して以下の行を追加した.

bind:*::

pid ファイル置場のパーミッション設定

pid ファイル置場である, /usr/local/bind/var/run/ を bind 所有にする.

# chown bind:bind /usr/local/bind/var/run/

各設定ファイルの編集

named.conf

ika より /usr/local/bind/etc/namedb/named.conf を /usr/local/bind/etc/namedb/ にコピー. ただし tako に namedb というディレクトリはもともとなかったのでつくった. ファイルは以下のようになっていた. (コメントアウトは除く)

acl my-network {
        133.30.110.0/24;
        133.30.109.0/25;
        127.0.0.1;
};

options {
        dump-file "/usr/local/bind/etc/cache_dump.db";
        directory "/usr/local/bind/etc/namedb";
        pid-file "/usr/local/bind/var/run/named.pid";
        recursion yes;
        allow-query { "my-network"; };
};

zone "." {
        type hint;
        file "named.root";
};

zone "localhost" {
        type master;
        file "localhost.zone";
};

zone "0.0.127.in-addr.arpa" {
        type master;
        file "localhost.rev";
};

controls {
          inet 127.0.0.1 port 953
                   allow { 127.0.0.1; } keys { "rndc-key"; };
};

include "/usr/local/bind/etc/rndc.key";

このなかで,options の項目の

dump-file "/usr/local/bind/etc/cache_dump.db";

の一行はマニュアルにはなかった.

localhost.zone

ika より /usr/local/bind/etc/namedb/localhost.rev を /usr/local/bind/etc/namedb/ にコピーし,ファイル内の"ika" という記述を "tako" に変更する.また,Serial には作業当日の日付と更新回数を書く. 書き換え後のファイルの中身は以下のようになった.

;       From: @(#)localhost.rev 5.1 (Berkeley) 6/30/90
; $FreeBSD: src/etc/namedb/PROTO.localhost.rev,v 1.6 2000/01/10 15:31:40 peter Exp $
;
; This file is automatically edited by the `make-localhost' script in
; the /etc/namedb directory.
;

$TTL    3600

@       IN      SOA     tako-itpass.scitec.kobe-u.ac.jp. root.tako- itpass.scitec.kobe-u.ac.jp.  (
                            2010101301 ; Serial
                               3600    ; Refresh
                               900     ; Retry
                               3600000 ; Expire
                               3600 )  ; Minimum
        IN      NS      tako-itpass.scitec.kobe-u.ac.jp.
        IN      A       127.0.0.1

localhost.rev

localhost.rev を localhost.zone という名前としてコピーし,ファイル内の"ika" という記述を "tako" に変更する.書き換え後のファイルの内容は以下のようになった.

;       From: @(#)localhost.rev 5.1 (Berkeley) 6/30/90
; $FreeBSD: src/etc/namedb/PROTO.localhost.rev,v 1.6 2000/01/10 15:31:40 peter Exp $
;
; This file is automatically edited by the `make-localhost' script in
; the /etc/namedb directory.
;

$TTL    3600

@       IN      SOA     tako-itpass.scitec.kobe-u.ac.jp. root.tako- itpass.scitec.kobe-u.ac.jp.  (
                             2010101301        ; Serial
                               3600    ; Refresh
                               900     ; Retry
                               3600000 ; Expire
                               3600 )  ; Minimum
        IN      NS      tako-itpass.scitec.kobe-u.ac.jp.
1       IN      PTR     localhost.scitec.kobe-u.ac.jp.

named.root

起動テスト

以下のコマンドを実行して bind を起動する.

# /usr/local/bind/sbin/named -u bind -c /usr/local/bind/etc/namedb/named.conf

/var/log/syslog を見て, 確認すると以下のようであった.

Oct 13 15:23:19 tako-itpass kernel: [662702.734048] warning: `named' uses 32-bit capabilities (legacy support in use) 
Oct 13 15:23:19 tako-itpass named[3381]: starting BIND 9.7.2-P2 -u bind -c /usr/local/bind/etc/namedb/named.conf
Oct 13 15:23:19 tako-itpass named[3381]: built with '--prefix=/usr/local/bind'
Oct 13 15:23:19 tako-itpass named[3381]: using up to 4096 sockets
Oct 13 15:23:19 tako-itpass named[3381]: loading configuration from '/usr/local/bind/etc/namedb/named.conf'
Oct 13 15:23:19 tako-itpass named[3381]: /usr/local/bind/etc/namedb/named.conf:50: open: /usr/local/bind/etc/rndc.key: file not found
Oct 13 15:23:19 tako-itpass named[3381]: loading configuration: file not found
Oct 13 15:23:19 tako-itpass named[3381]: exiting (due to fatal error)

/usr/local/bind/etc/rndc.key はこの時点では存在していないので怒られた.そのためマニュアル順ではなく,先に以下の rndc の設定を行うことにした.

rndc の設定

rndc-confgen を実行し, 必要な設定ファイルの「もと」を生成する.

rndc-confgen の出力を /usr/local/bind/etc/rndc.conf として保存する.

# rndc-confgen > /usr/local/bind/etc/rndc.conf

rndc.conf の中身は以下のようになっている.

# Start of rndc.conf
key "rndc-key" {
        algorithm hmac-md5;
        secret "SZN/mCIMkFJmFJ/98jlcMQ==";
};

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 "SZN/mCIMkFJmFJ/98jlcMQ==";
# };
#
# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf

secret "SZN/mCIMkFJmFJ/98jlcMQ=="; は認証に用いる共通鍵(パスワード)を表す.ここに挙げているのは例であって, 実際の設定とは異なる.

rndc.conf のコメントアウトされている箇所のうち, key で始まる4行を /usr/local/bind/etc/rndc.key として保存した. 念のため, rndc.conf のコメントアウトされている箇所を削除した.

最後にパーミッションを以下のように変更した.

root@new:/usr/local/bind/etc# chgrp -R staff .
root@new:/usr/local/bind/etc# chown bind rndc.key
root@new:/usr/local/bind/etc# chmod 600 rndc.key
root@new:/usr/local/bind/etc# chmod 640 rndc.conf
root@new:/usr/local/bind/etc# chown bind namedb/named.conf
root@new:/usr/local/bind/etc# chmod 640 namedb/named.conf

ただし,gate の設定が終わった後にグループを itpadmin に変更する作業が残っている.

rndc のテスト

以下のコマンドを実行する.

root@tako:/usr/local/bind/etc# rndc reload

以下のように表示されたが,問題ないとした.

WARNING: key file (/usr/local/bind/etc/rndc.key) exists, but using default configuration file (/usr/local/bind/etc/rndc.conf)
server reload successful

起動テスト 2

rndc の設定ができたので,再び起動のコマンドを実行し,/var/log/syslog/ を確認すると以下のようであった.(最後の部分のみ抜粋)

Oct 13 16:51:00 tako-itpass named[11992]: /usr/local/bind/etc/namedb/named.conf:46: couldn't add command channel 127.0.0.1#953: address in use
Oct 13 16:51:00 tako-itpass named[11992]: the working directory is not writable
Oct 13 16:51:00 tako-itpass named[11992]: zone 0.0.127.in-addr.arpa/IN: loaded serial 2010101301
Oct 13 16:51:00 tako-itpass named[11992]: zone localhost/IN: loaded serial 2010101301
Oct 13 16:51:00 tako-itpass named[11992]: managed-keys-zone ./IN: loading from master file managed-keys.bind failed: file not found
Oct 13 16:51:00 tako-itpass named[11992]: managed-keys-zone ./IN: loaded serial 0
Oct 13 16:51:00 tako-itpass named[11992]: running

今度は起動したが,いろいろとエラーがでた.

/usr/local/bind/etc/namedb/named.conf:46: couldn't add command channel 127.0.0.1#953: address in use

については,前にテスト起動したプロセスが残っていてポートが使われていたためのエラーだった.前の bind のプロセスをすべて終了させ起動させると,エラーはでなくなった.

the working directory is not writable

については,ika でも同様になることから問題ないとした.

managed-keys-zone 関連のエラーについては /usr/local/bind/etc/namedb の下に,managed-keys.bind という空のファイルを作成すると出なくなった.

syslog のエラーはなくなったので, ps でも bind 起動を確認した.

ps -ax
11961 ?        Ss     0:00 /usr/local/bind/sbin/named -u bind -c /usr/local /bind/etc/namedb/named.conf

ファイルフォーマットチェック

named.conf とゾーン, 各々の整合性を確認した.

root@tako:/usr/local/bind/etc# named-checkconf /usr/local/bind/etc/namedb/named.conf

何も出力されなければ正常である.

さらに以下を実行する.

root@tako:/usr/local/bind/etc# named-checkzone localhost localhost.zone

以下のように表示された.

zone localhost/IN: loaded serial 20071025
OK

起動スクリプトの用意

サーバの起動時に自動的に起動させるため, bind の起動スクリプトを用意する.

Debian の bind パッケージに含まれる/etc/init.d/bind を元に起動スクリプトを bind 用に多少書き換えたものが bind から入手できる. このファイルを /etc/init.d/bind にダウンロードする.

# cd /etc/init.d
# wget http://itpass.scitec.kobe-u.ac.jp/~itpass/epa/bind/bind

以下のように所有者とパーミッションを設定した.

# chown root:root /etc/init.d/bind
# chmod 755 /etc/init.d/bind

念のため, bind スクリプトの start, stop, restart の動作確認を行う. bind というコマンドが別に存在するため,絶対パスで bind ファイルを指定しなければならない.

# /etc/init.d/bind start
# /etc/init.d/bind stop
# /etc/init.d/bind restart

コマンドごとに ps ax で動作を確認した.

ランレベルごとに bind の動作を設定する.

# update-rc.d bind defaults

を実行し,以下のように表示された.

Adding system startup for /etc/init.d/bind ...
 /etc/rc0.d/K20bind -> ../init.d/bind
 /etc/rc1.d/K20bind -> ../init.d/bind
 /etc/rc6.d/K20bind -> ../init.d/bind
 /etc/rc2.d/S20bind -> ../init.d/bind
 /etc/rc3.d/S20bind -> ../init.d/bind
 /etc/rc4.d/S20bind -> ../init.d/bind
 /etc/rc5.d/S20bind -> ../init.d/bind

さらに, tako を reboot し, 起動時に bind が起動することを確認した.

サーバ停止

このままの設定では, 何らかの原因で tako を DNS サーバとして参照してしまうと tako が itpass.scitec.kobe-u.ac.jp であるとなりすましてしまう不具合が発生するので, DNS サーバは ITPASS サーバ交代の時まで停止する.

DNS サーバ (bind) を停止.

# /etc/init.d/bind stop

起動時に bind を起動しないようにする.

# update-rc.d -f bind remove

サーバを再起動し, bind が起動していないことを確認した.

Last modified:2010/11/22 14:34:56
Keyword(s):
References:[[ITPASS2010]2010年度サーバ構築ログ]