软件安装
yum install bind
主节点配置:
[root@ named]# cat /etc/named.conf
options {
listen-on port 53 { 127.0.0.1;72.7.99.50;72.7.99.117; };
// listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
// statistics-file "/var/named/data/named_stats.txt";
// memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
// recursion yes;
// dnssec-enable yes;
// dnssec-validation yes;
/* Path to ISC DLV key */
// bindkeys-file "/etc/named.iscdlv.key";
// managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
[root@ named]# cat /etc/named.rfc1912.zones
zone "anetest.com" IN {
type master;
file "anetest.com.zone";
allow-transfer {72.7.99.51;};
};
[root@ named]# cat /var/named/anetest.com.zone
$TTL 1D
@ IN SOA @ anetest.com. (
201904191 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS master.anetest.com.
IN NS slave.anetest.com.
* IN A 72.7.99.1
master IN A 72.7.99.50
slave IN A 72.7.99.51
web IN A 72.7.6.4
参数解析
#vim /var/naemd/anetest.com.zone
$TTL 1D
@ 2D IN SOA dns1 admin.magedu.com. (
200005 ; serial #版本号,版本号可以任意数值,位数不能超过10个
1D ; refresh #更新间隔时间,1D表示一天
1H ; retry #同步数据失败后,再次尝试同步间隔时间。1H表示1小时
1W ; expire #一直不能同步数据,此间隔时间后从服务器不再提供解析服务
3H ) ; minimum #错误请求间隔时间,此时间内不再重启查询,直接将结果返回给客户端
NS dns1 #指明服务器名称
dns1 2D IN A 172.18.24.17 #服务器IP
www CNAME web #指明www为web的别名
web A 172.18.24.26 #域名对应的IP
从DNS配置
[root@pdnserver02 slaves]# cat /etc/named.conf
options {
listen-on port 53 { 127.0.0.1;72.7.99.51;72.7.99.50;};
// listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
// statistics-file "/var/named/data/named_stats.txt";
// memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
// recursion yes;
// dnssec-enable yes;
// dnssec-validation yes;
/* Path to ISC DLV key */
// bindkeys-file "/etc/named.iscdlv.key";
// managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
[root@ slaves]# cat /etc/named.rfc1912.zones
zone "anetest.com" IN {
type slave;
file "slaves/anetest.com.zone";
masters { 72.7.99.50; };
};
[root@ slaves]# cat /var/named/slaves/anetest.com.zone
$ORIGIN .
$TTL 86400 ; 1 day
anetest.com IN SOA anetest.com. anetest.com. (
201904191 ; serial
86400 ; refresh (1 day)
3600 ; retry (1 hour)
604800 ; expire (1 week)
10800 ; minimum (3 hours)
)
NS master.anetest.com.
NS slave.anetest.com.
$ORIGIN anetest.com.
* A 72.7.99.1
web A 72.7.6.4
master A 72.7.99.50
slave A 72.7.99.51
搭建过程中出现问题:
1、主从同步问题
(1)删除从库/var/named/slaved/目录下的文件,文件不同步
通过修改主库的 监听地址,添加本机地址 listen-on port 53 { 127.0.0.1;72.7.99.51;72.7.99.50;};
(2)修改anetest.com.zone 文件中的配置,从库不同步
通过修改 anetest.com.zone 文件中的 201904191 ; serial 值,然后service named reload 可以同步
(3)主从不通步的原因3 anetest.com.zone NS写的有问题
IN NS master.anetest.com.
IN NS slave.anetest.com.
检查语法:
named-checkconf
重新载入服务:
# service named reload
触发同步过程的原因有4种:
1.从域名服务器刚刚启动;
2.主域名服务器的Serial值增大;
3.执行了rndc?reload命令;
4.到了主从服务器的同步更新时间。
rndc reload #从主服务器同步解析数据到从服务器上
dig -t axfr anetest.com
[root@pdnserver02 ~]# dig +trace pda.anetest.com
禁用IPv6
error (network unreachable) resolving 'com/DNSKEY/IN': 2001:503:231d::2:30#53
error (network unreachable) resolving 'com/DNSKEY/IN': 2001:503:a83e::2:30#53
该报错是由于启用了ipv6的原因导致的,虽然我们在/etc/named.conf中将listen项的IPv6配置已禁用,但是在named.ca配置中还有13台根域的ipv6配置。所以还需要如下两种方法中的任一种来关闭ipv6的使用。
方法1:修改/etc/sysconfig/named配置
直接编辑配置文件/etc/sysconfig/named:
OPTIONS="whatever" 改为 OPTIONS="-4"
# 注意OPTIONS选项的值可以是:whatever、-4、-6中的一个
方法2:完全禁用IPv6
这部分可以参看我的博文 centos关闭ipv6 --- 这里有提供一些老版本的关闭方法。这里也提下在centos6下的关闭方法:
配置文件/etc/sysconfig/network,然后 将NETWORKING_IPV6=YES改为NETWORKING=no;关闭ip6tables这个服务;向/etc/modprobe.conf文件中,添加如下内容:
alias ipv6 off
alias net-pf-10 off
反向dns配置
主dns添加
cat /etc/named.rfc1912.zones
zone "lx.com" IN {
type master;
file "lx.com.zone";
};
zone "0.168.192.in-addr.arpa" IN {
type master;
file "192.168.0.206.zone";
};
对应zone区域的文件内容
[root@ named]# cat /var/named/lx.com.zone
$TTL 600
@ IN SOA dns.lx.com dnsadmin.lx.com (
20190423 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS master.lx.com.
IN NS slave.lx.com.
IN MX 10 dns.lx.com.
master IN A 192.168.0.206
slave IN A 192.168.0.207
mail IN A 192.168.0.202
www IN A 192.168.0.203
lx IN A 192.168.0.206
ns2 IN A 192.168.0.207
lxt IN A 192.168.0.204
lxx IN A 192.168.0.204
lp IN A 192.168.0.205
xxlip IN A 192.168.0.208
[root@ named]# cat /var/named/192.168.0.206.zone
$TTL 600
@ IN SOA dns.lx.com dnsadmin.lx.com (
20190422 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS master.lx.com.
IN NS slave.lx.com.
201 IN PTR dns.lx.com.
202 IN PTR mail.lx.com.
203 IN PTR www.lx.com.
206 IN PTR lx.lx.com.
207 IN PTR ns2.lx.com.
204 IN PTR lxx.lx.com.
205 IN PTR lp.lx.com.
208 IN PTR xxlip.lx.com.
备dns添加
cat /etc/named.rfc1912.zones
zone "lx.com" IN {
type slave;
masters { 192.168.0.206; };
file "slaves/lx.com.zone";
};
zone "0.168.192.in-addr.arpa" IN {
type slave;
masters { 192.168.0.206; };
file "slaves/192.168.0.206.zone";
};