上一篇笔记 CentOS7.6域名服务器配置(一)使用Bind配置主从DNS服务器 记录下Bind配置主从DNS服务。并且配置了2个测试使用的域名 demo.com 和 example.com
在客户端10.116.72.4上配置域名解析服务器,并验证
# 配置
vi /etc/resolv.conf
nameserver 10.116.72.6
nameserver 10.116.72.7
# 验证 1
ping www.example.com
PING www.example.com (10.116.72.4) 56(84) bytes of data.
64 bytes from demo.com (10.116.72.4): icmp_seq=1 ttl=64 time=0.021 ms
# 验证 2
ping www.baidu.com 你会发现并无法解析
出现上面除了*.example.com *.demo.com之外的其他域名都无法解析,这是因为正常配置的Bind域名服务器只能解析配置的域名,那么如何配置可以解析之外的域名呢,这里就用到了forward功能了。
vi /etc/named.conf
options {
//省略其他... ....
recursion yes;
forward first;
/* 这里配置转发器有阿里联通,google域名服务
forwarders {
223.5.5.5;
223.6.6.6;
114.114.114.114;
8.8.8.8;
8.8.4.4;
};
}
* 重启named服务,配置生效
```bash
systemctl restart named.service
dig www.baidu.com @10.116.72.6
; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> www.baidu.com @10.116.72.6
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10323
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 13, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 0 IN CNAME www.a.shifen.com.
www.a.shifen.com. 299 IN A 39.156.66.18
www.a.shifen.com. 299 IN A 39.156.66.14
;; AUTHORITY SECTION:
. 108329 IN NS l.root-servers.net.
. 108329 IN NS c.root-servers.net.
. 108329 IN NS f.root-servers.net.
. 108329 IN NS j.root-servers.net.
. 108329 IN NS m.root-servers.net.
. 108329 IN NS g.root-servers.net.
. 108329 IN NS b.root-servers.net.
. 108329 IN NS a.root-servers.net.
. 108329 IN NS h.root-servers.net.
. 108329 IN NS d.root-servers.net.
. 108329 IN NS e.root-servers.net.
. 108329 IN NS k.root-servers.net.
. 108329 IN NS i.root-servers.net.
;; Query time: 159 msec
;; SERVER: 10.116.72.6#53(10.116.72.6)
;; WHEN: Thu Jul 18 15:52:53 CST 2019
;; MSG SIZE rcvd: 312
我这里的bind服务器10.116.72.6/7都是我用来测试的。我们企业还有产线使用的内部域名解析服务器,例如10.116.71.10/11 内部域名区域(zone)是eju.local。这个域名一看就不是标准域名,只用于内部主机解析。
上面的转发器转发的都是公网真实域名(当然也可以在那里配置添加上10.116.71.10/11,但是这里的IP地址是轮询方式解析的,效率会低些)。
Bind提供的转发区域的概念,允许把 DNS 配置为查找特定域名的时候才使用转发器。例如,可以使业务主机服务器将所有对刚刚提到的eju.local
结尾的域名查询都转发给eju.local
的名字服务器(NS)。
# 因为eju.local不是标准的域名格式,需要关闭dnssec验证
cat /etc/named.conf
options {
//省略其他配置 ... ...
dnssec-enable no;
dnssec-validation no;
}
# 配置转发区域
cat /etc/named.rfc1912.zones
//省略其他配置 ... ...
zone "eju.local" IN {
type forward;
forwarders { 10.116.71.10; 10.116.71.11; };
};
systemctl restart named.service
dig fang-source.fang.eju.local @10.116.72.6
; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> fang-source.fang.eju.local @10.116.72.6
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9586
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 6, ADDITIONAL: 7
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;fang-source.fang.eju.local. IN A
;; ANSWER SECTION:
fang-source.fang.eju.local. 601947 IN A 10.116.186.4
fang-source.fang.eju.local. 601947 IN A 10.116.186.5
;; AUTHORITY SECTION:
eju.local. 601947 IN NS dns4.eju.local.
eju.local. 601947 IN NS dns2.eju.local.
eju.local. 601947 IN NS dns6.eju.local.
eju.local. 601947 IN NS dns7.eju.local.
eju.local. 601947 IN NS dns5.eju.local.
eju.local. 601947 IN NS dns3.eju.local.
;; ADDITIONAL SECTION:
dns3.eju.local. 604778 IN A 10.99.73.6
dns7.eju.local. 604778 IN A 10.116.71.11
dns5.eju.local. 604778 IN A 10.106.71.11
dns2.eju.local. 604778 IN A 10.99.73.5
dns6.eju.local. 604778 IN A 10.116.71.10
dns4.eju.local. 604778 IN A 10.106.71.10
;; Query time: 1 msec
;; SERVER: 10.116.72.6#53(10.116.72.6)
;; WHEN: Thu Jul 18 16:09:07 CST 2019
;; MSG SIZE rcvd: 297
备注:如果没有关闭dnssec验证,无法解析非标准格式的域名,日志会报如下错误
validating ./NS: got insecure response; parent indicates it should be secure
validating eju.local/SOA: got insecure response; parent indicates it should be secure
no valid RRSIG resolving 'dns.eju.local/DS/IN': 10.116.71.10#53
validating eju.local/SOA: got insecure response; parent indicates it should be secure
no valid RRSIG resolving 'dns.eju.local/DS/IN': 10.116.71.11#53
insecurity proof failed resolving 'dns.eju.local/A/IN': 10.116.71.11#53
validating dns.eju.local/A: got insecure response; parent indicates it should be secure
insecurity proof failed resolving 'dns.eju.local/A/IN': 10.116.71.10#53
这种情况需要设置如下 : 文件 /etc/named.conf
dnssec-enable no;
dnssec-validation no;