* 说明:本例子以linux为例,但操作步骤对于windows系统也同样适用。
# 假定域名为localdomain,如服务器名字为 devsrv1-scan.localdomain
# 为带.localdomain的域名字配置查找机器:
[root@DEVSRV1 named]# cat /var/named/localdomain.zone
$TTL 86400
@ IN SOA localhost root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS localhost
localhost IN A 127.0.0.1
devsrv1-scan IN A 172.29.31.6
devsrv2-scan IN A 172.29.31.7
这样的话,遇到“devsrv1-scan.localdomain”,会到"localdoamin.zone"文件中查找“devsrv1-scan”对应的ip地址,即“172.29.31.6”
# 配置 dns服务文件 /etc/named.caching-nameserver.conf
1)默认使用127.0.0.1的53端口侦听,需要改变ip地址
[root@DEVSRV2 etc]# grep 53 /etc/named.caching-nameserver.conf
listen-on port 53 { 127.0.0.1;172.29.31.7; };
listen-on-v6 port 53 { ::1; };
2)默认只能从本机(即localhost) nslookup,需要加上any(共三处)以便允许其他机器使用nslookup:
allow-query { localhost;any; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view localhost_resolver {
match-clients { localhost;any;};
match-destinations { localhost;any;};
recursion yes;
include "/etc/named.rfc1912.zones";
};
* 注意:/etc/named.*.conf为总的服务配置文件入口
# 启动 dns服务
sh /etc/init.d/named start
# 配置dns客户端(即解析程序)
使用 nameserver 指定dns服务器
[root@DEVSRV1 named]# cat /etc/resolv.conf
#172.29.31.6为上面启动dns服务的ip
nameserver 172.29.31.6
#search localdomain
# dns客户端查找
[root@DEVSRV2 etc]# nslookup devsrv-scan.localdomain
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: devsrv-scan.localdomain
Address: 172.29.31.6
Name: devsrv-scan.localdomain
Address: 172.29.31.7