文章目录
llinux–DNS服务 之 主从复制
一:实验环境
第一台机器做主服务器,操作系统是centOS7.6,地址为:20.0.0.41;
第二台机器做从服务器,操作系统是centOS7.6,地址为:20.0.0.42;
所有机器采用Nat网络模式
二:实验步骤
2.1主从服务器都关闭防火墙
[root@localhost ~]# setenforce 0 关闭增强性安全功能
[root@localhost ~]# iptables -F 清空防火墙规则
2.2主从服务器都安装BIND
[root@localhost ~]# yum -y install bind
[root@localhost ~]# rpm -qc bind 查看bind有哪些配置文件
2.3BIND的配置文件
/etc/logrotate.d/named
/etc/named.conf 主配置文件
/etc/named.iscdlv.key
/etc/named.rfc1912.zones 区域配置文件
/etc/named.root.key
/etc/rndc.conf
/etc/rndc.key
/etc/sysconfig/named
/var/named/named.ca
/var/named/named.empty
/var/named/named.localhost区域数据配置文件
2.4编辑 主配置文件 /etc/named.conf
主从服务器修改内容一样
options {
13 listen-on port 53 { any; }; 括号里改为any 监听所有
14 listen-on-v6 port 53 { ::1; };
15 directory “/var/named”;
16 dump-file “/var/named/data/cache_dump.db”;
17 statistics-file “/var/named/data/named_stats.txt”;
18 memstatistics-file “/var/named/data/named_mem_stats.txt”;
19 recursing-file “/var/named/data/named.recursing”;
20 secroots-file “/var/named/data/named.secroots”;
21 allow-query { any; }; 括号里改为any 允许所有地址访问
2.5编辑区域配置文件 /etc/named.rfc1912.zones
[root@localhost ~]# vim /etc/named.rfc1912.zones
主服务器配置
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "johnson.com" IN {
type master;
file "johnson.com.zone";
allow-update { none; };
};
从服务器配置
2.6将区域数据配置文件复制到johnson.com.zone
[root@localhost ~]# cd /var/named
[root@localhost named]# cp -p named.localhost johnson.com.zone
2.7区域数据配置文件 /var/named/named.localhost
只需编辑主服务器的,从服务器会自动同步主服务器的区域数据配置文件
$TTL 1D
@ IN SOA johnson.com. admin.johnson.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS johnson.com.
IN MX 10 mail.johnson.com.
A 127.0.0.1
www IN A 192.168.66.66
* IN A 6.6.6.6
[root@localhost named]# systemctl start named 启动bind
[root@localhost named]# netstat -naup 查看网络连接情况
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:5353 0.0.0.0:* 8586/avahi-daemon:
udp 0 0 127.0.0.1:53 0.0.0.0:* 13735/named
udp 0 0 192.168.122.1:53 0.0.0.0:* 9601/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 9601/dnsmasq
udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
udp 0 0 127.0.0.1:323 0.0.0.0:* 8565/chronyd
udp 0 0 0.0.0.0:671 0.0.0.0:* 8557/rpcbind
udp 0 0 0.0.0.0:47946 0.0.0.0:* 8586/avahi-daemon:
2.8设置提供域名解析服务的服务器的IP地址
[root@localhost named]# echo "nameserver 192.168.138.128" > /etc/resolv.conf
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl start named
[root@localhost named]# netstat -nuap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:5353 0.0.0.0:* 8670/avahi-daemon:
udp 0 0 192.168.138.100:53 0.0.0.0:* 84103/named
udp 0 0 192.168.122.1:53 0.0.0.0:* 84103/named
udp 0 0 127.0.0.1:53 0.0.0.0:* 84103/named
udp 0 0 192.168.122.1:53 0.0.0.0:* 10665/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 10665/dnsmasq
udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
udp 0 0 0.0.0.0:35031 0.0.0.0:* 8670/avahi-daemon:
udp 0 0 127.0.0.1:323 0.0.0.0:* 8652/chronyd
udp 0 0 0.0.0.0:751 0.0.0.0:* 8637/rpcbind
udp6 0 0 ::1:53 :::* 84103/named
udp6 0 0 :::111 :::* 1/systemd
udp6 0 0 ::1:323 :::* 8652/chronyd
udp6 0 0 :::751 :::* 8637/rpcbind
[root@localhost named]# host www.johnson.com
www.johnson.com has address 192.168.138.128
8637/rpcbind
[root@localhost named]# host www.johnson.com
www.johnson.com has address 192.168.138.128
[外链图片转存中...(img-scaWfX03-1594544405141)]
![mark](https://imgconvert.csdnimg.cn/aHR0cDovL2xpdWRvbmdsaWFuZy5vc3MtY24tYmVpamluZy5hbGl5dW5jcy5jb20vaW1nLzIwMjAwNzA5LzA5MzkwODkwNy5wbmc?x-oss-process=image/format,png)