bind9の設定

会社のサーバをリプレイス中。
まずは第一弾でbind9のインストール。

まずは/usr/local/etc/pkgtools.confにオプションを書いてインストール

vi /usr/local/etc/pkgtools.conf

    • -

MAKE_ARGS = {
'dns/bind9' => 'WITH_PORT_REPLACES_BASE_BIND9=yes',
}

    • -

portinstall dns/bind9


次に/etc/rc.confにOS起動時に立ち上がるように記述

vi /etc/rc.conf

    • -

named_enable="YES"
named_program="/usr/sbin/named"
named_flags="-4 -u bind"
named_pidfile="/var/run/named/pid"
named_chrootdir="/var/named"
named_chroot_autoupdate="YES"
named_symlink_enable="YES"

    • -


/var/named/etc/namedbに移動して設定ファイルをいじる準備をする

cd /var/named/etc/namedb
sh make-localhost
vi chg_cache.sh

    • -

#!/bin/sh
#generated by pmobiuse

/usr/bin/dig @a.root-servers.net . ns >/etc/namedb/named.root.new 2>&1

case `cat /etc/namedb/named.root.new` in
echo "The root.hints file update has FAILED."
echo "This is the dig output reported:"
echo
cat /etc/namedb/named.root.new
exit 0
;;
esac

echo "The root.hints file has been updated to contain the following infomation:"
cat /etc/namedb/named.root.new

chown root.wheel /etc/namedb/named.root.new
chmod 444 /etc/namedb/named.root.new
rm -f /etc/namedb/named.root.old
mv -f /etc/namedb/named.root /etc/namedb/named.root.old
mv -f /etc/namedb/named.root.new /etc/namedb/named.root
kill -HUP `/bin/cat /var/run/named.pid`
echo "The nameserver has been restarted to ensure that the update is complete."
echo "The previous root.hints file is now called /etc/namedb/named.root.old"
exit 0

    • -

rndc-confgen -a -b 512 -r /dev/urandom -u bind
chown bind:bind rndc.key && chmod 0400 rndc.key
cp rndc.conf.sample rndc.conf
chmod 600 rndc.conf
vi rndc.conf

    • -

options {
default-server localhost;
default-key "rndc-key";
};

server localhost {
key "rndc-key";
};

#key "key" {
# algorithm hmac-md5;
# secret "c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K";
#};
include "/etc/namedb/rndc.key";

    • -

chg_cache.shはIPv6のために bind9 を覚えるページ(fkimura.com)からいただきました。
rootサーバが変更時の対応に使う。
rndcはbindを再起動せずに設定を反映するために使うらしいけど、いつも再起動してるからあまり使ったことがない。


いよいよ
bindの設定ファイルいじります。
とりあえず内部向けに動いていればいいのでnamed.confはこんな感じ

vi named.conf

    • -

include "/etc/namedb/rndc.key";

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

options {
directory "/etc/namedb";
pid-file "/var/run/named/pid";
dump-file "/var/dump/named_dump.db";
statistics-file "/var/stats/named.stats";

version "";
listen-on-v6 { none; };
auth-nxdomain yes;

allow-transfer { none; };
//slave server none;
};

logging {
channel bind_log {
file "/var/log/named.log" versions 3 size 2m;
severity dynamic;
print-time yes;
print-category yes;
};
category xfer-out {
bind_log;
};
category default {
default_syslog;
};
};

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

//zone "0.0.127.IN-ADDR.ARPA" {
// type master;
// file "master/localhost.rev";
//};

// RFC 3152
//zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA" {
// type master;
// file "master/localhost-v6.rev";
//};

acl "intra" {
172.29.0.0/16;
127.0.0.1;
};

view "internal" {
match-clients { intra; };
recursion yes;

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

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

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

zone "example.jp" {
type master;
file "master/example.jp.zone";
};

zone "29.172.in-addr.arpa" {
type master;
file "master/29.172.in-addr.arpa";
};
};

    • -


最後にゾーンファイルを作成して終わり

cd master
cp localhost.rev 0.0.127.in-addr.arpa
vi 0.0.127.in-addr.arpa

    • -

$TTL 3600

@ IN SOA gw.example.jp. root.gw.example.jp. (
20060501 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS gw.example.jp.
1 IN PTR localhost.

    • -

vi 29.172.in-addr.arpa

    • -

$TTL 3600

@ IN SOA gw.example.jp. root.gw.example.jp. (
20060501 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS gw.example.jp.
1 IN PTR localhost.

    • -

vi example.jp.zone

    • -

$TTL 3600
vi example.jp.zone
@ IN SOA gw.example.jp. root.gw.example.jp. (
20060428 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS gw.example.jp.
IN MX 10 gw.example.jp.
IN A 172.29.0.1
gw IN A 172.29.0.1

    • -

以上(また長いエントリになった...)。