CentOSサーバー構築マニュアル

BIND インストール


■BIND9インストール
[root@ns1 ~]# yum -y install bind caching-nameserver bind-chroot

■named.conf編集
[root@ns1 ~]# vi /var/named/chroot/etc/named.conf

↓下記を記入
//
// named.conf for Red Hat caching-nameserver
//

options {
	version "unknown";
	directory "/var/named";
	allow-query      { localhost; localnets; };
	allow-recursion  { localhost; localnets; };
	allow-transfer   { localhost; localnets; };
	forwarders       { xxx.xxx.xxx.xx1; xxx.xxx.xxx.xx2; };
};

//
// a caching only nameserver config
//
controls {
	inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};

logging {
	category lame-servers { null; };
};

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

	zone "." IN {
		type hint;
		file "named.ca";
	};

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

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

	zone "centos.orz" {
		type master;
		file "centos.orz.local";
	};
};

include "/etc/rndc.key";

※黄色い部分は環境に合わせて変更してください。

ヒント

forwardersのxxx.xxx.xxx.xx1はISPのプライマリDNSサーバーのIPアドレス。
forwardersのxxx.xxx.xxx.xx2はISPのセカンダリDNSサーバーのIPアドレス。
forwardersは省略することも可能ですが、記入しておくと
自分自身で名前解決できない場合に回送してくれます。
1.168.192.in-addr.arpaとは192.168.1を反対にした数字です。
IPアドレスが192.168.3.*の場合は3.168.192.in-addr.arpaになります。

■named.conf編集 (固定IPの場合)
[root@ns1 ~]# vi /var/named/chroot/etc/named.conf

↓最終行に下記を記入
view "external"{
	match-clients { any; };
	recursion no;

	zone "centos.orz" {
		type master;
		file "centos.orz.zone";
		allow-transfer { yyy.yyy.yyy.yyy; };
	};
};

※黄色い部分は環境に合わせて変更してください。
※yyy.yyy.yyy.yyy はセカンダリDNSサーバーのIPアドレスです。

■localhost逆引き
[root@ns1 ~]# vi /var/named/chroot/var/named/0.0.127.in-addr.arpa

↓下記を記入
$TTL 86400
@	IN	SOA	ns1.centos.orz.	root.centos.orz. (
	2010050400	;Serial
	28800		;Refresh
	7200		;Retry
	604800		;Expire	
	86400		;Minimum
)

	IN	NS	ns1.centos.orz.
1	IN	PTR	localhost.

※黄色い部分は環境に合わせて変更してください。

■内部正引き
[root@ns1 ~]# vi /var/named/chroot/var/named/centos.orz.local

↓下記を記入
$TTL	86400
@	IN	SOA	ns1.centos.orz.	root.centos.orz.  (
	2010050400	;Serial
	28800		;Refresh
	7200		;Retry
	604800		;Expire
	86400		;Minimum
)
	IN	NS	ns1.centos.orz.
	IN	MX	10	mail.centos.orz.
@	IN	A	192.168.1.10
*	IN	A	192.168.1.10
mail	IN	A	192.168.1.10

※黄色い部分は環境に合わせて変更してください。

■内部逆引き
[root@ns1 ~]# vi /var/named/chroot/var/named/1.168.192.in-addr.arpa

↓下記を記入
$TTL	86400
@	IN	SOA	ns1.centos.orz.	root.centos.orz.(
	2010050400	;Serial
	28800		;Refresh
	7200		;Retry
	604800		;Expire
	86400		;Minimum
)
	IN	NS	ns1.centos.orz.
10	IN	PTR	centos.orz.

※黄色い部分は環境に合わせて変更してください。
※最終行の10はサーバーのローカルIPアドレス192.168.1.10の10です。

■外部正引き (固定IPの場合)
[root@ns1 ~]# vi /var/named/chroot/var/named/centos.orz.zone

↓下記を記入
$TTL	86400
@	IN	SOA	ns1.centos.orz.	root.centos.orz.  (
	2010050400	;Serial
	28800		;Refresh
	7200		;Retry
	604800		;Expire
	86400		;Minimum
)
	IN	NS	ns1.centos.orz.
	IN	MX	10	mail.centos.orz.
@	IN	A	zzz.zzz.zzz.zzz
*	IN	A	zzz.zzz.zzz.zzz
mail	IN	A	zzz.zzz.zzz.zzz
centos.orz. IN TXT "v=spf1 a mx ~all"

※黄色い部分は環境に合わせて変更してください。
※zzz.zzz.zzz.zzz は固定IPアドレスです。

ヒント

TTL(Time To Live)はレコードの生存時間を設定します。
SOA(Start Of Authority)レコードにはゾーン空間についての権限などの情報を記載します。
Serial:ゾーン情報のバージョンを管理する。(慣習的に日付+更新分の2桁を付ける)
Refresh:セカンダリサーバがプライマリサーバに更新があったか確認する間隔。
Retry:上記の問い合わせで応答が得られなかった場合サイド問い合わせる間隔。
Expire:この時間を越えるとセカンダリサーバはデータを破棄する。
Minimum:キャッシュサーバが情報を保存する時間。
NSレコード:ネームサーバを記載する。
MXレコード:メールサーバを記載する。
Aレコード:ホストに対するIPアドレスを記載する。
PTRレコード:IPアドレスからホスト名(FQDN)に変換するレコード。

■ルートゾーン最新化
[root@ns1 ~]# dig . ns @128.63.2.53 > /var/named/chroot/var/named/named.ca

■BIND起動
[root@ns1 ~]# echo 'nameserver 127.0.0.1' > /etc/resolv.conf
[root@ns1 ~]# /etc/rc.d/init.d/named start
[root@ns1 ~]# chkconfig named on
[root@ns1 ~]# chkconfig --list named
named           0:off   1:off   2:on    3:on    4:on    5:on    6:off

■BIND動作確認
[root@ns1 ~]# dig @127.0.0.1 centos.orz soa

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> @127.0.0.1 centos.orz soa
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31510
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;centos.orz.                    IN      SOA

;; ANSWER SECTION:
centos.orz.             86400   IN      SOA     ns1.centos.orz. root.centos.orz. 2010050400 28800 7200 604800 86400

;; AUTHORITY SECTION:
centos.orz.             86400   IN      NS      ns1.centos.orz.

;; ADDITIONAL SECTION:
ns1.centos.orz.         86400   IN      A       192.168.1.10

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May  5 02:05:10 2010
;; MSG SIZE  rcvd: 103

[root@ns1 ~]# dig @127.0.0.1 centos.orz ns

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> @127.0.0.1 centos.orz ns
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20784
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;centos.orz.                    IN      NS

;; ANSWER SECTION:
centos.orz.             86400   IN      NS      ns1.centos.orz.

;; ADDITIONAL SECTION:
ns1.centos.orz.         86400   IN      A       192.168.1.10

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May  5 02:05:36 2010
;; MSG SIZE  rcvd: 62

[root@ns1 ~]# dig @127.0.0.1 ns1.centos.orz

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> @127.0.0.1 ns1.centos.orz
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62552
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;ns1.centos.orz.                        IN      A

;; ANSWER SECTION:
ns1.centos.orz.         86400   IN      A       192.168.1.10

;; AUTHORITY SECTION:
centos.orz.             86400   IN      NS      ns1.centos.orz.

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May  5 02:05:55 2010
;; MSG SIZE  rcvd: 62

[root@ns1 ~]# dig @127.0.0.1 -x 192.168.1.10

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> @127.0.0.1 -x 192.168.1.10
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1769
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;10.1.168.192.in-addr.arpa.     IN      PTR

;; ANSWER SECTION:
10.1.168.192.in-addr.arpa. 86400 IN     PTR     centos.orz.

;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400   IN      NS      ns1.centos.orz.

;; ADDITIONAL SECTION:
ns1.centos.orz.         86400   IN      A       192.168.1.10

;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May  5 02:06:15 2010
;; MSG SIZE  rcvd: 101

[root@ns1 ~]# dig @127.0.0.1 www.centos.org

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_4.2 <<>> @127.0.0.1 www.centos.org
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12443
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 0

;; QUESTION SECTION:
;www.centos.org.                        IN      A

;; ANSWER SECTION:
www.centos.org.         120     IN      A       72.232.194.162

;; AUTHORITY SECTION:
centos.org.             14400   IN      NS      ns1.centos.org.
centos.org.             14400   IN      NS      ns2.centos.org.
centos.org.             14400   IN      NS      ns3.centos.org.

;; Query time: 2652 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May  5 02:06:32 2010
;; MSG SIZE  rcvd: 102

※黄色い部分は環境に合わせて変更してください。

外部に公開する場合

プロトコル(TCP/UDP)ポート53番(DNS)を開放。


Home PageTop Last updated 2010-08-25

このサイトはリンクフリーです。ご自由にリンクしてください。 Copyright centos.server-manual.com