在上一篇博客中我已经搭建好了一个本地DNS服务器,能够实现正向反向解析,那么我们只需要加入一台从DNS服务器即可完成,我们来开始配置主从服务器:
一.主DNS服务器上面的额外配置:
# cat chinasoft.com.zone
$TTL 43200
@ IN SOA dns.chinasoft.com admin.chinasoft.com. (
2014031104 ;
2H ;
10M ;
7D ;
1D) ;
@ IN NS dns
@ IN NS dns2
@ IN MX 10 mail
dns IN A 192.168.3.17
mail IN A 192.168.3.10
www IN A 192.168.3.11
dns2 IN A 192.168.3.18
pop IN CNAME mail
ftp IN CNAME www
=====
检测区域解析库配置文件语法:
# named-checkzone "chinasoft.com" chinasoft.com.zone
zone chinasoft.com/IN: loaded serial 2014031102
OK
二.从DNS服务器的配置
安装bind:yum install -y bind-libs bind-utils bind.x86_64
检查安装情况:
rpm -qa bind*
bind-libs-9.8.2-0.47.rc1.el6.x86_64
bind-utils-9.8.2-0.47.rc1.el6.x86_64
bind-9.8.2-0.47.rc1.el6.x86_64
主配置文件的配置:
我们可以将主DNS服务器的主配置文件/etc/named.conf复制一份到从DNS服务器上
测试主从之间的网络连通性:
# ping -c 3 192.168.3.17
PING 192.168.3.17 (192.168.3.17) 56(84) bytes of data.
64 bytes from 192.168.3.17: icmp_seq=1 ttl=64 time=0.409 ms
64 bytes from 192.168.3.17: icmp_seq=2 ttl=64 time=0.470 ms
64 bytes from 192.168.3.17: icmp_seq=3 ttl=64 time=0.261 ms
复制主DNS服务器的主配置文件到从服务器还需要修改以下配置注释掉一些我们不要的项:
scp /etc/named.conf 192.168.3.18:/etc/
# vim /etc/named.conf
查看配置文件
cat /etc/named.conf
options {
// listen-on port 53 { 192.168.3.18; };
// 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 no;
dnssec-validation no;
dnssec-lookaside no;
*/
/* 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";
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-transfer { none; };
};
include "/etc/named.rfc1912.zones";
//include "/etc/named.root.key";
从服务器区域配置文件:/etc/named.conf
在下面添加一个从DNS区域:
由于从服务器上/var/named/目录的权限是属主root属组named,且属组named没有写权限;如果给这个目录写权限就会造成系统的不安全;所以软件定义了目录下有个slaves文件,来保存从主服务器接收的配置文件
安装好后根据我们上面说的、切换去我们的主服务器的区域文件目录下、注意、这里是主服务器的区域文件、编辑tanxw.com.zone这个文件加一条新的NS记录、两台DNS服务都可以互相成为主从:
# vim /etc/named.rfc1912.zones
zone "chinasoft.com" IN {
type slave;
file "slaves/chinasoft.com.zone";
masters { 192.168.3.17; };
};
zone "3.168.192.in-addr.arpa" IN{
type slave;
file "slaves/192.168.3.zone";
masters { 192.168.3.17; };
};
检查一下语法正确与否:
named-checkconf /etc/named.rfc1912.zones
再改一下你的从NDS服务器地址、编辑/etc/resolv.conf:
# vim /etc/resolv.conf
domain chinasoft.com
search chinasoft.com
nameserver 192.168.3.18
重新启动从服务器named服务
service named restart
服务启动后都要看一下日志、这个是一个好习惯、不管有没有问题都要看一眼、下面说明数据已经开始传输了:
再去看一下/var/named/salves/目录下有没有生成一个chinasoft.com.zone的文件:
# ls /var/named/slaves/
192.168.3.zone chinasoft.com.zone
再看一下/var/named/slaves/chinasoft.com.zone的内容:
从上面看出我们的正向、反向区域解析库文件传输成功了。
三、从DNS服务器测试
除了dig命令和host命令,还有nslookup命令可以测试DNS服务器的状态,并且windows平台也有这个工具,我们就先在windows物理机平台来测试一下哦!然后我们再用从服务器解析一下:
# dig -t NS chinasoft.com @192.168.3.18
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> -t NS chinasoft.com @192.168.3.18
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16202
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2
;; QUESTION SECTION:
;chinasoft.com. IN NS
;; ANSWER SECTION:
chinasoft.com. 43200 IN NS dns2.chinasoft.com.
chinasoft.com. 43200 IN NS dns.chinasoft.com.
;; ADDITIONAL SECTION:
dns.chinasoft.com. 43200 IN A 192.168.3.17
dns2.chinasoft.com. 43200 IN A 192.168.3.18
;; Query time: 0 msec
;; SERVER: 192.168.3.18#53(192.168.3.18)
;; WHEN: Tue Sep 13 14:13:44 2016
;; MSG SIZE rcvd: 100
四、添加weiji.chinasoft.com的解析举例:
vim /var/named/chinasoft.com.zone
添加解析,注意修改serial的值,重启服务service named restart
服务端的其他配置:
master_dns:
cat /etc/resolv.conf
; generated by /sbin/dhclient-script
domain chinasoft.com
search chinasoft.com
nameserver 192.168.3.17
cat /etc/hosts
192.168.3.17 dns.chinasoft.com
slave_dns:
cat /etc/resolv.conf
; generated by /sbin/dhclient-script
domain chinasoft.com
search chinasoft.com
nameserver 192.168.3.18
cat /etc/hosts
192.168.3.18 dns2.chinasoft.com
客户端的配置:
cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.3.17
nameserver 192.168.3.18
nameserver 202.96.128.166
推荐hostname设置和解析的内网域名一致
hostname和/etc/sysconfig/network
如:
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=dns.chinasoft.com