测试环境为CentOS 6.9,本机IP为47.94.215.189
安装相关程序包,仅仅是测试目的,暂不安装bind-chroot
~]# yum install -y bind bind-utils bind-libs
bind:
服务脚本:/etc/rc.d/init.d/named
主配置文件:/etc/named.conf,/etc/named.rfc1912.zones,/etc/rndc.key
解析库文件:/var/named/ZONE_NAME.ZONE
(1) 一台物理服务器可以同时为多个区域提供解析
(2) 必须要有根区域文件,named.ca
(3) 应该有两个(如果包括IPv6,应该更多)事项localhost和本地会换的解析
rndc:remote name domain controller,默认与bind安装在同一主机,且只能通过127.0.0.1来连接named进程,提供辅助性的管理功能,953/tcp
主配置文件:
全局配置:options { }
日志系统配置:logging { }
区域定义:本机能够为哪些zone进行解析,简要定义哪些zone
zone "ZONE_NAME" IN {}
缓存名称服务器的配置:
监听外部地址即可
dnssec:
建议测试时关闭dnssec
dnssec-enable yes; --> dnssec-enable no
dnssec-validation yes; --> dnssec-validation no
主DNS名称服务器:
(1) 在主配置文件中定义区域
zone "ZONE_NAME" IN {
type {master|slave|hint|forward};
file "ZONE_NAME.zone";
}
(2) 定义区域解析库文件
出现的内容:
宏定义
资源记录
假设已经从域名注册机构拿到域名www.lushenle.com,IP地址为47.94.215.189
(1) 编辑/etc/named.rfc1912.zones文件,在文件尾部加入如下内容即可
zone "lushenle.com" IN {
type master;
file "lushenle.com.zone";
};
(2)在/var/named/目录下创建名为lushenle.com.zone的文件
~]# vim /var/named/lushenle.com.zone
1 $TTL 1D 2 $ORIGIN lushenle.com. 3 @ IN SOA ns.lushenle.com. admin.lushenle.com. ( 4 20171107001 5 1H 6 5M 7 7D 8 1D ) 9 IN NS ns 10 IN MX 10 mx 11 ns1 IN A 47.94.215.189 12 mx1 IN A 47.94.215.189 13 www IN A 47.94.215.189 14 ftp IN CNAME www
虽然为测试,但在实际生产环境中,处于安全考虑,将文件权限改为640,属组改为named组
~]# chmod 640 /var/named/lushenle.com.zone
~]# chown :named /var/named/lushenle.com.zone
修改/etc/named.conf文件,在修改之前最好先备份一下
~]# cp -v /etc/named.conf{,.bak}
~]# vim /etc/named.conf
1 options { 2 listen-on port 53 { 47.94.215.189; 127.0.0.1; }; 3 directory "/var/named"; 4 dump-file "/var/named/data/cache_dump.db"; 5 statistics-file "/var/named/data/named_stats.txt"; 6 memstatistics-file "/var/named/data/named_mem_stats.txt"; 7 allow-query { any; }; 8 recursion yes; 9 10 dnssec-enable no; 11 dnssec-validation no; 12 13 }; 14 15 logging { 16 channel default_debug { 17 file "data/named.run"; 18 severity dynamic; 19 }; 20 }; 21 22 zone "." IN { 23 type hint; 24 file "named.ca"; 25 }; 26 27 include "/etc/named.rfc1912.zones"; 28 include "/etc/named.root.key";
此时可检查一下主配置文件与区域配置文件是否存在错误
~]# named-checkconf
~]# named-checkzone "lushenle.com" /var/named/lushenle.com.zone
如果不存在错误即可启动服务,并进行测试
~]# service named start
~]# service named restart #不建议随意重启服务
~]# service named reload #重载服务,不重启
~]# rndc reload #重载服务,不重启
测试:
~]# dig -t A www.lushenle.com @47.94.215.189 +trace
~]# dig -t NS www.lushenle.com @47.94.215.189 +rrace +recurse
~]# host -t A www.lushenle.com 47.94.215.189