オーソドックスに bind で。
Ubuntu-11.10-server-amd64 で確認。
作成 2012.03.24
更新 2012.03.31
更新 2012.03.31
Ubuntu で DNS サーバー
構成
example.com ドメインのDNSサーバーを作成する。
正引きと逆引きを作成。内容は以下のとおり。
| 設定 | 値 (秒) |
| Default TTL | 3600 |
| Primary Name Server | dns.example.com. |
| Administrator Mail Address | root@example.com. |
| Serial (ゾーンファイルのバージョン番号) | 1 |
| Refresh (セカンダリDNSサーバーが更新確認に来る間隔) | 86400 |
| Retry (セカンダリDNSサーバーが更新確認に失敗した場合の再試行間隔) | 600 |
| Expire (セカンダリDNSサーバーが更新確認に失敗した場合のゾーン情報の有効期間) | 2419200 |
| Negative Cache (レコードなしの情報の有効期間) | 600 |
| ホスト | タイプ | レコード |
| @ | NS | dns.example.com |
| @ | MX | 10 mail.example.com. |
| dns | A | 192.168.0.102 |
| ldap | A | 192.168.0.103 |
| A | 192.168.0.104 | |
| webmail | A | 192.168.0.105 |
| webmail2 | A | 192.168.0.106 |
| ホスト | タイプ | レコード |
| 102 | PTR | dns.example.com. |
| 103 | PTR | ldap.example.com. |
| 104 | PTR | mail.example.com. |
| 105 | PTR | webmail.example.com. |
| 106 | PTR | webmail2.example.com. |
| ホスト | タイプ | レコード |
| @ | NS | dns.example.com |
| @ | MX | 10 mail.example.com. |
| dns | A | 192.0.2.102 |
| A | 192.0.2.104 | |
| webmail | A | 192.0.2.105 |
| webmail2 | A | 192.0.2.106 |
| ホスト | タイプ | レコード |
| 102 | PTR | dns.example.com. |
| 104 | PTR | mail.example.com. |
| 105 | PTR | webmail.example.com. |
| 106 | PTR | webmail2.example.com. |
インストール
普通に。
$ sudo apt-get install bind9設定ファイルは /etc/bind 配下に。ゾーンファイルは /var/cache/bind 配下にそれぞれ保存される。
設定
/etc/bind/named.conf view を追加して、外部・内部アクセスを定義
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local
include "/etc/bind/named.conf.options";
acl "internal-view" { 127.0.0.0/8; 192.168.0.0/24; };
acl "dns-servers" { 127.0.0.1; 192.168.0.102; 192.0.2.102; };
view "internal" {
match-clients { internal-view; };
allow-query { internal-view; };
allow-recursion { internal-view; };
allow-transfer { dns-servers; };
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";
zone "example.com" {
type master;
file "example.com.internal";
allow-update { none; };
};
zone "0.168.192.in-addr.arpa" {
type master;
file "0.168.192.in-addr.arpa.internal";
allow-update { none; };
};
zone "2.0.192.in-addr.arpa" {
type master;
file "2.0.192.in-addr.arpa.both";
allow-update { none; };
};
};
view "external" {
match-clients { any; };
allow-query { any; };
allow-recursion { none; };
allow-transfer { dns-servers; };
zone "example.com" {
type master;
file "example.com.external";
allow-update { none; };
};
zone "2.0.192.in-addr.arpa" {
type master;
file "2.0.192.in-addr.arpa.both";
allow-update { none; };
};
};
/etc/bind/named.conf.options デフォルト
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
// forwarders {
// 0.0.0.0;
// };
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
/etc/bind/named.conf.local コメントアウトを外す
// // Do any local configuration here // // Consider adding the 1918 zones here, if they are not used in your // organization include "/etc/bind/zones.rfc1918";/etc/bind/zones.rfc1918 これを含め参照先もデフォルト。
zone "10.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "16.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "17.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "18.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "19.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "20.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "21.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "22.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "23.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "24.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "25.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "26.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "27.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "28.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "29.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "30.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "31.172.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
zone "168.192.in-addr.arpa" { type master; file "/etc/bind/db.empty"; };
/etc/bind/named.conf.default-zones これを含め参照先もデフォルト。
// prime the server with knowledge of the root servers
zone "." {
type hint;
file "/etc/bind/db.root";
};
// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912
zone "localhost" {
type master;
file "/etc/bind/db.local";
};
zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};
zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};
zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};
/var/cache/bind/example.com.internal 新規作成
$TTL 3600
@ IN SOA dns.example.com. root.example.com. (
1 ; Serial
86400 ; Refresh
600 ; Retry
2419200 ; Expire
600 ) ; Negative Cache TTL
;
@ IN NS dns.example.com.
@ IN MX 10 mail.example.com.
dns IN A 192.168.0.102
ldap IN A 192.168.0.103
mail IN A 192.168.0.104
webmail IN A 192.168.0.105
webmail2 IN A 192.168.0.106
/var/cache/bind/example.com.external 新規作成
$TTL 3600
@ IN SOA dns.example.com. root.example.com. (
1 ; Serial
86400 ; Refresh
600 ; Retry
2419200 ; Expire
600 ) ; Negative Cache TTL
;
@ IN NS dns.example.com.
@ IN MX 10 mail.example.com.
dns IN A 192.0.2.102
mail IN A 192.0.2.104
webmail IN A 192.0.2.105
webmail2 IN A 192.0.2.106
/var/cache/bind/0.168.192.in-addr.arpa.internal 新規作成
$TTL 3600
@ IN SOA dns.example.com. root.example.com. (
1 ; Serial
86400 ; Refresh
600 ; Retry
2419200 ; Expire
600 ) ; Negative Cache TTL
;
@ IN NS dns.example.com.
102 IN PTR dns.example.com.
103 IN PTR ldap.example.com.
104 IN PTR mail.example.com.
105 IN PTR webmail.example.com.
106 IN PTR webmail2.example.com.
/var/cache/bind/2.0.192.in-addr.arpa.both 新規作成
$TTL 3600
@ IN SOA dns.example.com. root.example.com. (
1 ; Serial
86400 ; Refresh
600 ; Retry
2419200 ; Expire
600 ) ; Negative Cache TTL
;
@ IN NS dns.example.com.
102 IN PTR dns.example.com.
104 IN PTR mail.example.com.
105 IN PTR webmail.example.com.
106 IN PTR webmail2.example.com.
設定ファイルの書式チェック
named.conf に長々と設定を書き込んだのは、このファイルしかチェックされないため。
問題がなければ、何も表示されない。
問題がなければ、何も表示されない。
$ named-checkconfzone ファイルのチェックは、ドメイン名 ゾーンファイル名の順
$ named-checkzone example.com example.com.internal zone example.com/IN: loaded serial 1 OK
起動オプションの設定
/etc/default/bind9 のファイルで起動オプションが変更できる。
IPv4 にしか対応していない場合は、-4 を追加することで、IPv6 の通信を抑制できる。
/etc/default/bind9
IPv4 にしか対応していない場合は、-4 を追加することで、IPv6 の通信を抑制できる。
/etc/default/bind9
# run resolvconf? RESOLVCONF=yes # startup options for the server OPTIONS="-u bind -4"
起動
ゾーンファイルに問題があっても正常に起動してしまうため、普通は別ウインドウを開き tail で監視しながらサービスを起動する。
$ tail -f /var/log/syslogその状態でサービスを起動する。すでに起動している場合は restart
$ sudo service bind9 start
ログ
ログは /var/log/syslog に記録され、自動的にローテーションされる。