DNS 主从同步
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DNS 主从同步相关的知识,希望对你有一定的参考价值。
dns主从同步
环境
两台台centos7.4版本的虚拟机,主虚拟机IP为:192.168.100.139, 从虚拟机IP:192.168.100.140.两台虚拟机均安装bind。虚拟机均关闭防护墙
systemctl stop firewalld.service
setenforce 0
yum install bind -y
实验
在主虚拟机上编辑。
按照要求修改配置文件:
主配置文件:vim /etc/named.conf
修改前
options {
listen-on port 53 { 127.0.0.1; };
.......
allow-query { localhost; };
修改后
listen-on port 53 { 192.168.100.139; };
......
allow-query { any; };
编辑区域配置文件:
vim /etc/named.rfc1912.zones
复制模板,
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
修改
zone "benet.com" IN {
type master;
file "benet.com.zone";
allow-transfer { 192.168.100.140; }; //从服务器地址。允许传输的地址
};
保存退出
编辑区域数据文件:
cp -p /var/named/named.localhost /var/named/benet.com.zone
vim /var/named/benet.com.zone
修改前:
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
修改后
$TTL 1D
@ IN SOA @ admin (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 192.168.100.139
www IN A 192.168.100.139
保存退出
从虚拟机上编辑:
编辑主配置文件
修改前:
options {
listen-on port 53 { 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 { localhost; };
修改后:
options {
listen-on port 53 { 192.168.100.140; }; //换为本机IP
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; };
保存退出
编辑区域配置文件
复制一份配置文件
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
修改后的:
zone "benet.com" IN {
type slave;
file "slaves/benet.com.zone";
masters { 192.168.100.139; }; //向此IP获取同步。
};
保存退出
查看slaves文件夹
[[email protected] named]# cd /var/named/
[[email protected] named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[[email protected] named]# cd slaves/
[[email protected] slaves]# ls
[[email protected] slaves]#
echo "nameserver 192.168.100.140" > /etc/resolv.conf
启动两台虚拟机的dns服务:
systemctl start named.service
再次查看slaves文件夹
[[email protected] slaves]# ls
benet.com.zone
本来没有文件,现在同步过来了
解析一下,结果没问题。成功。
[[email protected] slaves]# nslookup www.benet.com
Server: 192.168.100.140
Address: 192.168.100.140#53
Name: www.benet.com
Address: 192.168.100.139
[[email protected] slaves]#
以上是关于DNS 主从同步的主要内容,如果未能解决你的问题,请参考以下文章