一、创建DNS主服务器
1、安装bind并配置主配置文件
主服务器为CentOS 7,主服务地址为172.16.11.55
安装bind
[root@xinfeng ~]# yum install bind
安装完成后查看是否存在/var/named/named.ca
这个文件包含了互联网上根服务器对应的名字和地址
备份一下/etc/named.conf
配置主配置文件/etc/named.conf
[root@xinfeng named]# vim /etc/named.conf // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { listen-on port 53 { 172.16.11.55; 127.0.0.1; }; #这里要加入对外监听53端口的主机地址 // listen-on-v6 port 53 { ::1; }; #注释掉ipv6的设置 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 { any; }; #将这里改为any,表示服务器允许所有地址来查询 /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users. Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes; #这里为yes表示允许递归查询 // dnssec-enable yes; // dnssec-validation yes; /* Path to ISC DLV key */ // bindkeys-file "/etc/named.iscdlv.key"; // managed-keys-directory "/var/named/dynamic"; 从dnssec开始到此全部注释掉 pid-file "/run/named/named.pid"; session-keyfile "/run/named/session.key"; }; 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";
改完之后重启服务,查看53号端口是否对外监听
[root@xinfeng named]# systemctl restart named.service [root@xinfeng named]# ss -tunl | grep 53 udp UNCONN 0 0 172.16.11.55:53 *:* udp UNCONN 0 0 127.0.0.1:53 *:* tcp LISTEN 0 10 172.16.11.55:53 *:* tcp LISTEN 0 10 127.0.0.1:53 *:* tcp LISTEN 0 128 127.0.0.1:953 *:* tcp LISTEN 0 128 ::1:953 :::* #可以看到已经监听到53号端口上了
在主配置文件中定义区域,编辑/etc/named.rfc1912.zones
[root@xinfeng named]# vim /etc/named.rfc1912.zones // named.rfc1912.zones: // // Provided by Red Hat caching-nameserver package // // ISC BIND named zone configuration for zones recommended by // RFC 1912 section 4.1 : localhost TLDs and address zones // and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt // (c)2007 R W Franks // // See /usr/share/doc/bind*/sample/ for example named configuration files. // zone "localhost.localdomain" IN { type master; file "named.localhost"; allow-update { none; }; }; zone "localhost" IN { type master; file "named.localhost"; allow-update { none; }; }; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "1.0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; zone "0.in-addr.arpa" IN { type master; file "named.empty"; allow-update { none; }; }; #在最后增加了一个区域叫xinfeng.com zone "xinfeng.com" IN { #type是服务器类型,master表示为主服务器 type master; #file是区域解析库文件的名称,这个文件放在/var/named/下 file "xinfeng.com.zone"; };
2、配置正向区域解析,并用dig测试
编辑完后保存,然后到/var/named/下面去创建一个xinfeng.com.zone的文件
[root@xinfeng named]# vim xinfeng.com.zone $TTL 86400 #TTL表示客户端得到结果后的可缓存时长,单位是秒,这里是1天,可从全局继承 $ORIGIN xinfeng.com. #ORIGIN定义为xinfeng.com.【注意最后有一个点】,这里定义之后,就可用后面@代替xinfeng.com. @ IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( #SOA表示起始授权纪录,之后跟上当前区域主DNS的名称,然后跟上当前主区域的管理员邮箱,邮箱中的@用.替换 2016041718 #2016041718表示序列号,编辑一次此文件就必须手动加1 1H #1H表示刷新时间为1消失 5M #5M表示重试时间为5分钟 7D #7D表示过期时间为7天,也可以写成1W 1D ) #1D表示否定答案的时间为1天 IN NS ns1 #NS专用于表示当前区域的DNS服务器,之后必须跟一个A纪录 ns1 IN A 172.16.11.55 #A表示ipv4正向解析,ipv6为AAAA,这里解析ns1.xinfeng.com到172.16.11.55 www IN A 172.16.11.55 #这里解析www.xinfeng.com到172.16.11.55 ftp IN CNAME www #CNAME表示别名,这里解析ftp.xinfeng.com到www.xinfeng.com,最终解析到172.16.11.55
保存之后用named-check来检查主配置文件和区域解析文件是否有语法错误
[root@xinfeng named]# named-checkconf [root@xinfeng named]# named-checkzone "xinfeng.com" /var/named/xinfeng.com.zone zone xinfeng.com/IN: loaded serial 2016041718 OK
OK表示没有语法错误
之后一定要记得改变文件/var/named/xinfeng.com.zone的属组为named,并改变权限为640
[root@xinfeng named]# ll -rw-r--r--. 1 root root 190 4月 14 02:42 xinfeng.com.zone [root@xinfeng named]# chown :named xinfeng.com.zone [root@xinfeng named]# chmod 640 xinfeng.com.zone [root@xinfeng named]# ll -rw-r-----. 1 root named 190 4月 14 02:42 xinfeng.com.zone
然后重启named服务
[root@xinfeng named]# systemctl restart named.service
安装dig测试,dig在bind-utils包内
[root@xinfeng named]# yum install bind-utils [root@xinfeng named]# dig -t A xinfeng.com @172.16.11.55 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> -t A xinfeng.com @172.16.11.55 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7034 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;xinfeng.com. IN A ;; AUTHORITY SECTION: xinfeng.com. 86400 IN SOA ns1.xinfeng.com. admin.xinfeng.com.xinfeng.com. 2016041719 3600 300 604800 86400 ;; Query time: 0 msec ;; SERVER: 172.16.11.55#53(172.16.11.55) ;; WHEN: 四 4月 14 04:24:15 CST 2016 ;; MSG SIZE rcvd: 98 [root@xinfeng named]# dig -t A www.xinfeng.com @172.16.11.55 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> -t A www.xinfeng.com @172.16.11.55 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36364 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.xinfeng.com. IN A ;; ANSWER SECTION: www.xinfeng.com. 86400 IN A 172.16.11.55 ;; AUTHORITY SECTION: xinfeng.com. 86400 IN NS ns1.xinfeng.com. ;; ADDITIONAL SECTION: ns1.xinfeng.com. 86400 IN A 172.16.11.55 ;; Query time: 1 msec ;; SERVER: 172.16.11.55#53(172.16.11.55) ;; WHEN: 四 4月 14 04:24:56 CST 2016 ;; MSG SIZE rcvd: 94
可以看到测试能成功解析
3、配置反向区域解析
依然要在主配置文件定义区域,编辑/etc/named.rfc1912.zone
[root@xinfeng named]# vim /etc/named.rfc1912.zones zone "xinfeng.com" IN { type master; file "xinfeng.com.zone"; }; #在刚才的正向解析之后加入下面的内容,注意网络地址要反写 zone "11.16.172.in-addr.arpa" IN { type master; file "172.16.11.zone"; };
保存之后在/var/named/中增加172.16.11.zone的区域解析库文件
[root@xinfeng named]# vim 172.16.11.zone $TTL 86400 $ORIGIN 11.16.172.in-addr.arpa. @ IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( 2016041720 1H 5M 7D 1D ) IN NS ns1.xinfeng.com. 55 IN PTR ns1.xinfeng.com. 55 IN PTR www.xinfeng.com. #这里的不能有A或者AAAA纪录,PTR就是反向解析的意思,注意地址反写,其他的和正向解析没有区别
保存之后记得改属组和权限,并检查语法
[root@xinfeng named]# chmod 640 172.16.11.zone [root@xinfeng named]# chown :named 172.16.11.zone [root@xinfeng named]# named-checkzone "11.16.172.in-addr.arpa" /var/named/172.16.11.zone zone 11.16.172.in-addr.arpa/IN: loaded serial 2016041720 OK [root@xinfeng named]# named-checkconf
显示OK语法检测OK,重启服务,并用dig测试
[root@xinfeng named]# systemctl restart named.service [root@xinfeng named]# dig -x 172.16.11.55 @172.16.11.55 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> -x 172.16.11.55 @172.16.11.55 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50285 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;55.11.16.172.in-addr.arpa. IN PTR ;; ANSWER SECTION: 55.11.16.172.in-addr.arpa. 86400 IN PTR www.xinfeng.com. 55.11.16.172.in-addr.arpa. 86400 IN PTR ns1.xinfeng.com. ;; AUTHORITY SECTION: 11.16.172.in-addr.arpa. 86400 IN NS ns1.xinfeng.com. ;; ADDITIONAL SECTION: ns1.xinfeng.com. 86400 IN A 172.16.11.55 ;; Query time: 0 msec ;; SERVER: 172.16.11.55#53(172.16.11.55) ;; WHEN: 四 4月 14 04:09:54 CST 2016 ;; MSG SIZE rcvd: 131
可以看到测试正常
4、配置泛域名解析
编辑正向区域解析文件/var/nemad/xinfeng.com.zone,在其中加入*的A纪录,并且序列号加1
[root@xinfeng named]# vim /var/named/xinfeng.com.zone $TTL 86400 $ORIGIN xinfeng.com. @ IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( 2016041719 1H 5M 7D 1D ) IN NS ns1 ns1 IN A 172.16.11.55 www IN A 172.16.11.55 ftp IN CNAME www * IN A 172.16.11.55
检查语法错误
[root@xinfeng named]# named-checkzone "xinfeng.com" /var/named/xinfeng.com.zone zone xinfeng.com/IN: loaded serial 2016041719 OK
重载文件并用dig测试
[root@xinfeng named]# rndc reload server reload successful [root@xinfeng named]# dig -t A nfs.xinfeng.com @172.16.11.55 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> -t A nfs.xinfeng.com @172.16.11.55 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37887 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;nfs.xinfeng.com. IN A ;; ANSWER SECTION: nfs.xinfeng.com. 86400 IN A 172.16.11.55 ;; AUTHORITY SECTION: xinfeng.com. 86400 IN NS ns1.xinfeng.com. ;; ADDITIONAL SECTION: ns1.xinfeng.com. 86400 IN A 172.16.11.55 ;; Query time: 0 msec ;; SERVER: 172.16.11.55#53(172.16.11.55) ;; WHEN: 四 4月 14 04:21:13 CST 2016 ;; MSG SIZE rcvd: 94
测试正常
二、配置从服务器进行主从复制
新建一台从服务器,服务器系统为CentOS 6,地址为172.16.11.57
1、安装bind和bind-utils,并用dig测试看是否能解析到刚才我们配置的主服务
[root@xinfeng2 ~]# yum install bind [root@xinfeng2 ~]# yum install bind-utils [root@xinfeng2 ~]# service named start [root@xinfeng2 ~]# ss -tunl | grep 53 udp UNCONN 0 0 127.0.0.1:53 *:* tcp LISTEN 0 3 127.0.0.1:53 *:* tcp LISTEN 0 128 ::1:953 :::* tcp LISTEN 0 128 127.0.0.1:953 *:* [root@xinfeng2 ~]# dig -t axfr xinfeng.com @172.16.11.55 ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.7 <<>> -t axfr xinfeng.com @172.16.11.55 ;; global options: +cmd xinfeng.com. 86400 IN SOA ns1.xinfeng.com. admin.xinfeng.com.xinfeng.com. 2016041719 3600 300 604800 86400 xinfeng.com. 86400 IN NS ns1.xinfeng.com. ftp.xinfeng.com. 86400 IN CNAME www.xinfeng.com. ns1.xinfeng.com. 86400 IN A 172.16.11.55 www.xinfeng.com. 86400 IN A 172.16.11.55 xinfeng.com. 86400 IN SOA ns1.xinfeng.com. admin.xinfeng.com.xinfeng.com. 2016041719 3600 300 604800 86400 ;; Query time: 1 msec ;; SERVER: 172.16.11.55#53(172.16.11.55) ;; WHEN: Thu Apr 14 12:31:13 2016 ;; XFR size: 6 records (messages 1, bytes 191) dig -t axfr xinfeng.com @172.16.11.55
测试结果是正常的
2、配置从服务器的主配置文件
在/etc/named.conf中按照主服务配置一样修改,对外监听端口换成本机的也就是172.16.11.57
[root@xinfeng2 ~]# vim /etc/named.conf // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { listen-on port 53 { 172.16.11.57; 127.0.0.1; }; // 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 { any; }; recursion yes; // dnssec-enable yes; // dnssec-validation yes; // dnssec-lookaside auto; /* 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"; "/etc/named.conf" 43L, 1027C
编辑/etc/named.rfc1912.zone文件,在最后加入
[root@xinfeng2 ~]# vim /etc/named.rfc1912.zones zone "xinfeng.com" IN { type slave; masters { 172.16.11.55; }; file "slaves/xinfeng.com.zone"; };
也就是说他的区域解析库文件放置在/var/named/slaves/下叫xinfeng.com.zone,这里我们不需要去创建编辑这个区域解析库文件,因为之后主从同步之后,会自动获得这个文件,重启服务
[root@xinfeng2 ~]# service named restart Stopping named: . [ OK ] Starting named: [ OK ]
3、在主服务器上定义从服务器的正向解析库文件
编辑主DNS服务器的/var/named/xinfeng.com.zone文件在其中加入从服务器的A纪录和NS纪录,这里是ns2
[root@xinfeng named]# vim /var/named/xinfeng.com.zone $TTL 86400 $ORIGIN xinfeng.com. @ IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( 2016041720 1H 5M 7D 1D ) IN NS ns1 IN NS ns2 ns1 IN A 172.16.11.55 ns2 IN A 172.16.11.57 www IN A 172.16.11.55 ftp IN CNAME www
主服务器重载服务
[root@xinfeng named]# rndc reload server reload successful
到从服务器也就是172.16.11.57下查看区域解析库文件是否同步
[root@xinfeng2 ~]# cd /var/named/slaves/ [root@xinfeng2 slaves]# ls xinfeng.com.zone
可以看到区域解析库文件已同步成功
4、在从服务器上定义主配置文件,定义反向解析库文件位置
编辑主服务器也就是172.16.11.55的反向解析文件,加入ns2的A纪录和NS纪录,然后重载服务
[root@xinfeng named]# vim /var/named/172.16.11.zone $TTL 86400 $ORIGIN 11.16.172.in-addr.arpa. @ IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( 2016041720 1H 5M 7D 1D ) IN NS ns1.xinfeng.com. IN NS ns2.xinfeng.com. 55 IN PTR ns1.xinfeng.com. 57 IN PTR ns2.xinfeng.com. 55 IN PTR www.xinfeng.com. [root@xinfeng named]# rndc reload server reload successful
在从服务器上也就是172.16.11.57上编辑/etc/named.rfc1912.zone文件,在最后加入
[root@xinfeng2 ~]# vim /etc/named.rfc1912.zones zone "11.16.172.in-addr.arpa" IN { type slave; masters { 172.16.11.55; }; file "slaves/172.16.11.zone"; };
完成后重载从服务器,就会同步主服务器上的反向解析库文件
[root@xinfeng2 ~]# rndc reload server reload successful [root@xinfeng2 ~]# cd /var/named/slaves/ [root@xinfeng2 slaves]# ls 172.16.11.zone xinfeng.com.zone [root@xinfeng2 slaves]# cat 172.16.11.zone $ORIGIN . $TTL 86400 ; 1 day 11.16.172.in-addr.arpa IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( 2016041720 ; serial 3600 ; refresh (1 hour) 300 ; retry (5 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) NS ns1.xinfeng.com. $ORIGIN 11.16.172.in-addr.arpa. 55 PTR ns1.xinfeng.com. PTR www.xinfeng.com.
区域解析库文件同步成功
需要注意的是,主从服务器的bind版本需要一致,而且一定不要更改从服务器的区域解析库文件,只需要改主服务器的区域解析库文件。
三、子域授权
父域为172.16.11.55,子域为172.16.9.9
1、定义父域
进入父域服务器172.16.11.55,编辑/var/named/xinfeng.com.zone也就是父域的正向解析库文件,在其中加入子域的NS纪录和A纪录
[root@xinfeng ~]# vim /var/named/xinfeng.com.zone $TTL 86400 $ORIGIN xinfeng.com. @ IN SOA ns1.xinfeng.com. admin.xinfeng.com. ( 2016041720 1H 5M 7D 1D ) IN NS ns1 IN NS ns2 ns1 IN A 172.16.11.55 ns2 IN A 172.16.11.57 www IN A 172.16.11.55 ftp IN CNAME www tv IN NS ns1.ops ns1.ops IN A 172.16.9.9 [root@xinfeng ~]# named-checkzone "xinfeng.com" /var/named/xinfeng.com.zone zone xinfeng.com/IN: loaded serial 2016041720 OK [root@xinfeng ~]# rndc reload server reload successful
检查语法正确,并重载后,
2、定义子域
进入子域服务器172.16.9.9
新服务器重新编辑/etc/named.conf,之后开起服务
[root@tv.xinfeng.com ~]# vim /etc/named.conf [root@tv.xinfeng.com ~]# systemctl start named.service [root@tv.xinfeng.com ~]# ss -tunl | grep 53 udp UNCONN 0 0 172.16.9.9:53 *:* udp UNCONN 0 0 127.0.0.1:53 *:* tcp LISTEN 0 10 172.16.9.9:53 *:* tcp LISTEN 0 10 127.0.0.1:53 *:* tcp LISTEN 0 128 127.0.0.1:953 *:* tcp LISTEN 0 128 ::1:953 :::*
编辑子域172.16.9.9的/etc/named.rfc1912.zones ,在后面加入
[root@tv.xinfeng.com ~]# vim /etc/named.rfc1912.zones zone "tv.xinfeng.com" IN { type master; file "tv.xinfeng.com.zone"; }; [root@tv.xinfeng.com ~]# rndc reload server reload successful
编辑子域172.16.9.9的/var/named/tv.xinfeng.com.zone
[root@tv.xinfeng.com ~]# vim /var/named/tv.xinfeng.com.zone $TTL 1d $ORIGIN tv.xinfeng.com. @ IN SOA ns1.tv.xinfeng.com. admin.tv.xinfeng.com. ( 2016041722 1H 10M 3D 1D ) IN NS ns1 ns1 IN A 172.16.9.9 www IN A 172.16.9.9 [root@tv.xinfeng.com]# chown :named tv.xinfeng.com.zone [root@tv.xinfeng.com]# chmod 640 tv.xinfeng.com.zone [root@tv.xinfeng.com ~]# rndc reload server reload successful
3、测试解析
测试子域能否解析自己范围的
[root@tv.xinfeng.com]# dig -t A ns1.tv.xinfeng.com @172.16.9.9 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> -t A ns1.tv.xinfeng.com @172.16.9.9 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56031 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;ns1.tv.xinfeng.com.INA ;; ANSWER SECTION: ns1.tv.xinfeng.com. 86400 IN A 172.16.9.9 ;; AUTHORITY SECTION: tv.xinfeng.com. 86400 IN NS ns1.tv.xinfeng.com. ;; Query time: 0 msec ;; SERVER: 172.16.9.9#53(172.16.9.9) ;; WHEN: 一 3月 21 07:58:01 CST 2016 ;; MSG SIZE rcvd: 77
测试成功,测试父域能否解析子域的
[root@xinfeng ~]# dig -t A www.tv.xinfeng.com @172.16.11.55 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> -t A www.tv.xinfeng.com @172.16.11.55 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 61635 ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.tv.xinfeng.com. IN A ;; Query time: 2 msec ;; SERVER: 172.16.11.55#53(172.16.11.55) ;; WHEN: 四 4月 14 06:38:48 CST 2016 ;; MSG SIZE rcvd: 47
测试成功
四、区域转发
1、父域定义全部转发
在父域服务器172.16.11.55编辑/etc/named.conf主配置文件
[root@xinfeng ~]# vim /etc/named.conf #在options中注释掉 // allow-query { any; }; #在options中增加 forward first; forwarders { 114.114.114.114; }; [root@xinfeng ~]# rndc reload server reload successful
2、子域定义区域转发
在子域服务器172.16.9.9编辑/etc/named.rfc1912.zones文件,在最后添加zone
[root@tv.xinfeng.com]# vim /etc/named.rfc1912.zones zone "xinfeng.com" IN { type forward; forward only; forwarders { 172.16.11.55; }; }; [root@localhost named]# rndc reload server reload successful
【注意】:若全部转发和区域转发在一台服务器上同时启用,则能精确匹配区域转发的则区域转发,其他的由全部转发负责
五、view
1、编辑DNS服务器的主配置文件/etc/named.conf,将其中的默认zone剪切到/etc/named.rfc1912.zone中
[root@xinfeng ~]# vim /etc/named.conf #将以下删除 zone "." IN { type hint; file "named.ca"; }; [root@xinfeng ~]# vim /etc/named.rfc1912.zones #放在此文件最顶端
2、编辑/etc/named.conf,在顶端定义几个acl
[root@xinfeng ~]# vim /etc/named.conf acl mynet { 172.16.0.0/16; 127.0.0.0/8; };
3、编辑/etc/named.rfc1912.zone
[root@xinfeng ~]# vim /etc/named.rfc1912.zones view internal { match-clients { mynet; }; allow-recursion { mynet; }; zone { ...}; zone { ...}; zone{ ...}; }; #用view来控制所有zone [root@xinfeng ~]# named-checkconf [root@xinfeng ~]# systemctl restart named.service
把能和172.16.11.55的主机地址加入/etc/named.rfc1912.zone的match-clients,然后用dig测试,再删除测试
4、注意事项
一个bind服务器可定义多个view,每个view中可定义一个或多个zone
每个view用一来匹配一组客户端
多个view内可能需要对同一个区域进行解析,但使用不同的区域解析库文件
一旦启用了view,所有的zone都只能定义在view中
仅有必要在匹配到允许递归请求的客户所在view中定义根区域
客户端请求到达时,是自上而下检查每个view所服务的客户端列表
六、总结
配置一个DNS服务器的过程:
1、配置DNS主配置文件:/etc/named.conf
2、定义区域文件:/etc/named.rfc1912.zone
3、配置区域文件中对应的区域解析库文件:/var/named/ZONE_NAME.zone
4、重载服务:rndc reload
5、测试:dig
转载于:https://blog.51cto.com/xsllqs/1765640