主dns
安装包
[root@use05 ~]# yum install bind bind-utils -y
修改配置,主要是这几行,其它内容可不用修改;
listen-on port 53 { localhost; }; 表示监听所有地址的53端口;
allow-query { any; }; 允许任何人查询;
allow-transfer { 192.168.247.16; }; 只允许指定主机进行区域传送,这里指定的是从服务器;
[root@use05 ~]# vim /etc/named.conf
options {
listen-on port 53 { localhost; };
allow-query { any; };
allow-transfer { 192.168.247.16; };
};
创建域名数据库并添加rr记录
[root@use05 ~]# vim /var/named/mage.com.zone
$TTL 1D
@ IN SOA master.mage.com. admin.mage.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
NS slave
master A 192.168.75.15
slave A 192.168.75.16
www CNAME websrv
websrv A 192.168.75.15
websrv A 192.168.75.16
修改权限
[root@use05 ~]# chmod 640 /var/named/mage.com.zone
[root@use05 ~]# chown :named /var/named/mage.com.zone
[root@use05 ~]# ls -l /var/named/mage.com.zone
-rw-r----- 1 root named 313 Jul 17 10:46 /var/named/mage.com.zone
添加域名区域配置
[root@use05 ~]# vim /etc/named.rfc1912.zones
zone "mage.com" {
type master;
file "mage.com.zone";
};
语法检查
[root@use05 ~]# named-checkconf
[root@use05 ~]# named-checkzone mage.com /var/named/mage.com.zone
zone mage.com/IN: loaded serial 0
OK
启动服务
[root@use05 ~]# systemctl restart named.service
[root@use05 ~]# systemctl enable named.service
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
测试域名解析
[root@use05 ~]# host www.mage.com 192.168.247.15
Using domain server:
Name: 192.168.247.15
Address: 192.168.247.15#53
Aliases:
www.mage.com is an alias for websrv.mage.com.
websrv.mage.com has address 192.168.75.15
websrv.mage.com has address 192.168.75.16
从服器
安装包
[root@use06 ~]# yum install bind bind-utils -y
修改配置,只修改这三行,其它不用修改;
[root@use06 ~]# vim /etc/named.conf
options {
listen-on port 53 { localhost; };
allow-query { any; };
allow-transfer { none; };
};
添加域名区域配置
[root@use06 ~]# vim /etc/named.rfc1912.zones
zone "mage.com" {
type slave;
masters { 192.168.247.15; };
file "slaves/mage.com.zone.slave";
};
启动服务
[root@use06 ~]# systemctl restart named.service
[root@use06 ~]# systemctl enable named.service
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
测试
[root@use06 ~]# host www.mage.com 192.168.247.16
Using domain server:
Name: 192.168.247.16
Address: 192.168.247.16#53
Aliases:
www.mage.com is an alias for websrv.mage.com.
websrv.mage.com has address 192.168.75.16
websrv.mage.com has address 192.168.75.15
补充
主从同步有两种模式:推和拉,拉即由从服务器主动去安主服务器同步数据,这个是有时间间隔的;推则是由主服务器在有域名变更时向从服务器主动同步,推的配置是在主服务器的rr记录中加入从服务器的ns记录即可,本例是推方式。