折腾了几天,参考了《OReilly.DNS.And BIND 5th》之后,终于配置成功了DNS
环境是CentOS 5.6, BIND 9.3,总共分两步,第一步配置DNS服务器,第二步配置DNS Resolver
1. 参考上一篇Blog《Fix default BIND install on CentOS》,有如下环境,基于vmware workstation,有两台CentOS,网络接口方式是NAT
第一台: rac01.smartoffice.com
IP: 192.168.226.146
第二台: rac02.smartoffice.com
IP: 192.168.226.149
第一台是DNS服务器,他的ZONE DATA FILE以及named configuration file如下配置:
named.conf 配置
options {
directory "/var/named";
};
zone "smartoffice.com" in {
type master;
file "db.smartoffice.com";
};
zone "226.168.192.in-addr.arpa" in {
type master;
file "db.192.168.226";
};
-- zone data file (Address mapped to NAMES) db.192.168.226
226.168.192.in-addr.arpa. IN SOA rac01.smartoffice.com rac02.smartoffice.com(
1 ;serial
3h ;refresh after 3 hours
1h ;retry after 1 hour
1w ;expire after 1 week
1h) ;negative caching TTL of 1 hour
;
;NS Records
;
226.168.192.in-addr.arpa. IN NS rac01.smartoffice.com
;
;host addresses:
;
146.226.168.192.in-addr.arpa. IN PTR rac01.smartoffice.com
149.226.168.192.in-addr.arpa. IN PTR rac02.smartoffice.com
-- zone data file (Names mapped to Addresses) db.smartoffice.com
smartoffice.com. IN SOA rac01.smartoffice.com. rac02.smartoffice.com.(
1 ;serial
3h ;refersh after 3 hours
1h ;retry after 1 hour
1w ;expire after 1 week
1h) ;negative caching TTL of 1 hour
;
;NS Records:
;
smartoffice.com. IN NS rac01.smartoffice.com.
smartoffice.com. IN NS rac02.smartoffice.com.
;
;Host Addresses
;
localhost.smartoffice.com. IN A 127.0.0.1
rac01.smartoffice.com. IN A 192.168.226.146
rac02.smartoffice.com. IN A 192.168.226.149
;
;multi-home hosts
;none
2. 配置DNS Resolver: BIND默认的resolver文件是/etc/resolv.conf
vmware默认给/etc/resolv.conf设置了默认的DNS地址,我通过修改.bash_profile修改这个/etc/resolv.conf,
主DNS的本机(rac01.smartoffice.com),修改如下:
echo "domain smartoffice.com" > /etc/resolv.conf
echo "nameserver 192.168.226.146" >> /etc/resolv.conf
echo "nameserver 116.228.111.118" >>/etc/resolv.conf (这个地址是上海浦东电信的DNS,为了可以上网也增加了这条,事实是smartoffice.com已经被注册过,所以放在第二位DNS)
非DNS的机器(rac02.smartoffice.com),修改如下:
echo "search smartoffice.com" > /etc/resolv.conf
echo "nameserver 192.168.226.146" >> /etc/resolv.conf
echo "nameserver 116.228.111.118" >>/etc/resolv.conf
注明: a) domain 和search 指令,指定一个即可,domain后的域名也可以被用来寻址用,search之后的第一个域名,可以看作是本机所在局域网的域名,并且与domain指令在同一个文件中时,会覆盖domain的域名。
b) nameserver可以指定最多3个服务器地址,并且是IP,不能是域名服务的主机名