四、 配置唯缓存DNS服务
修改(若没有就添加)以下文件:
1./etc/resolv.conf 该文件指定域名服务器的IP和搜索的顺序。
----------------------------------------------------------------------------------------------------------------------
nameserver 202.103.44.5 //域名服务器的IP
search localdomain
----------------------------------------------------------------------------------------------------------------------
2./etc/nsswitch.conf 该文件处理host表和DNS的顺序,告诉系统哪里查找特定类型的配置信息(即服务),将以host开头的行替换为如下行:
hosts: files nisplus dns
替换后为:
----------------------------------------------------------------------------------------------------------------------
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files nisplus
shadow: files nisplus
group: files nisplus
#hosts: db files nisplus nis dns
hosts: files nisplus dns
# Example - obey only what nisplus tells us...
#services: nisplus [NOTFOUND=return] files
#networks: nisplus [NOTFOUND=return] files
#protocols: nisplus [NOTFOUND=return] files
#rpc: nisplus [NOTFOUND=return] files
#ethers: nisplus [NOTFOUND=return] files
#netmasks: nisplus [NOTFOUND=return] files
bootparams: nisplus [NOTFOUND=return] files
ethers: files
netmasks: files
networks: files
protocols: files nisplus
rpc: files
services: files nisplus
netgroup: files nisplus
publickey: nisplus
automount: files nisplus
aliases: files nisplus
----------------------------------------------------------------------------------------------------------------------
3../etc/named.conf
----------------------------------------------------------------------------------------------------------------------
options {
directory "/var/named"; //这里的/var/named用于存放下面3个配置文件,用户
//可以自己指定为别的的目录。
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};
//
// a caching only nameserver config
//
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
----------------------------------------------------------------------------------------------------------------------
对应的有以下3个配置文件,一般不需修改;
(1)./var/named/named.ca //系统自带,不要修改
(2)./var/named/named.local
----------------------------------------------------------------------------------------------------------------------
$TTL 86400
@ IN SOA localhost.
IN NS local
1 IN PTR localhost.
----------------------------------------------------------------------------------------------------------------------
(3)/var/named/localhost.zone ////系统自带,不要修改
----------------------------------------------------------------------------------------------------------------------
$TTL 86400
$ORIGIN localhost.
@ 1D IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN NS @
1D IN A 127.0.0.1
一切配置就绪,运行以下命令:
#service named restart 或
#/etc/init.d/named restart
使配置生效。用nslookup命令测试是否能够进行正确的地址解析。例如:
#nslookup www.sina.com.cn
----------------------------------------------------------------------------------------------------------------------
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig'' or `host'' programs instead. Run nslookup with
the `-sil[ent]'' option to prevent this message from appearing.
Server: 202.103.44.5
Address: 202.103.44.5#53
Non-authoritative answer:
www.sina.com.cn canonical name = jupiter.sina.com.cn.
Name: jupiter.sina.com.cn
Address: 218.201.44.8
Name: jupiter.sina.com.cn
Address: 218.201.44.9