上篇介绍了DNS正向解析,本文将继续介绍反向解析与主从复制等内容。域名反向解析即从IP地址到域名的映射。为了完成逆向域名解析,系统提供一个特别域,该特别域称为逆向解析域。
目录
正向解析相关内容参考:Linux动态分配IP与正向解析DNS-CSDN博客
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install bind bind-utils.x86_64 -y
#安装bind软件包和工具包
[root@localhost ~]# vim /etc/named.conf
[root@localhost ~]# vim /etc/named.rfc1912.zones
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -a fql.com.zone lisi.com.zone
[root@localhost named]# ll lisi.com.zone
-rw-r-----. 1 root named 389 1月 12 15:06 lisi.com.zone
[root@localhost named]# vim lisi.com.zone
[root@localhost named]# rndc reload #重新加载配置文件
server reload successful
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
DNS1=192.168.190.100
[root@localhost named]# systemctl restart network
[root@localhost named]# systemctl restart named
[root@localhost named]# host 192.168.190.102
102.190.168.192.in-addr.arpa domain name pointer www.lisi.com.
[root@localhost named]# host 192.168.190.103
103.190.168.192.in-addr.arpa domain name pointer ftp.lisi.com.
?注:dig 192.168.190.102 @192.168.190.100无法反向解析。
环境:主服务器地址:192.168.190.100;从服务器地址:192.168.190.101
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install bind bind-utils.x86_64 -y
#安装bind软件包和工具包
[root@localhost ~]# vim /etc/named.conf
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
DNS1=192.168.190.100
DNS2=192.168.190.101
主服务器:
[root@localhost ~]# vim /etc/named.rfc1912.zones #修改域名配置文件
zone "fql.com" IN {
type master; #类型主
file "fql.com.zone"; #文件地址在/var/named/下
allow-transfer { 192.168.190.101; }; #申明从服务器的地址
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -a named.localhost fql.com.zone
[root@localhost named]# vim fql.com.zone #修改数据库配置文件
$TTL 1D
@ IN SOA master.fql.com. admin.fql.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
NS slave
master A 192.168.190.100
slave A 192.168.190.101
www A 192.168.190.102
ftp A 192.168.190.103
mail A 192.168.190.104
abc CNAME www
* A 192.168.190.100
@ A 192.168.190.100
[root@localhost named]# dig www.fql.com #dig解析
;; SERVER: 192.168.190.100#53(192.168.190.100)
关于数据库配置文件内容上篇已做介绍,这里不过多赘述。?
从服务器:
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "fql.com" IN {
type slave; #类型从
file "slaves/fql.com.zone"; #文件地址在/var/named/slaves/下
masters { 192.168.190.100; }; #申明主服务器的地址
};
[root@localhost named]# systemctl restart named #重启mind服务,首次可以获取主服务器数据库文件
[root@localhost named]# ls slaves/
fql.com.zone
[root@localhost named]# dig www.fql.com
;; SERVER: 192.168.190.100#53(192.168.190.100) #此时可以看见是主服务器解析
主服务器:
[root@localhost ~]# systemctl stop named
[root@localhost ~]# host www.fql.com
www.fql.com has address 192.168.190.102 #速度略慢依然可以解析
[root@localhost ~]# dig www.fql.com
;; SERVER: 192.168.190.101#53(192.168.190.101) #此时可以看见是从服务器解析
[root@localhost ~]# systemctl restart named #重启bind服务器
[root@localhost ~]# dig www.fql.com
;; SERVER: 192.168.190.100#53(192.168.190.100) #恢复为主服务器解析
[root@localhost ~]# vim /var/named/fql.com.zone
[root@localhost ~]# systemctl restart named
[root@localhost ~]# host www.fql.com
www.fql.com has address 192.168.190.88 #解析后已更新新的地址
环境:将linux服务器配置两块网卡;ens33:192.168.190.100,ens36:12.0.0.1。
目的效果:实现不通网段访问服务器域名解析不同的ip地址
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install bind bind-utils.x86_64 -y
#安装bind软件包和工具包
[root@localhost ~]# vim /etc/named.conf
13 listen-on port 53 { any; };
21 allow-query { any; };
54 //zone "." IN { #将根配置文件删除或者注释
55 // type hint;
56 // file "named.ca";
[root@localhost ~]# vim /etc/named.rfc1912.zones
view "lan" {
match-clients { 192.168.190.0/24; }; #匹配网段
zone "fql.com" IN {
type master;
file "fql.com.lan";
};
zone "." IN { #根配置文件
type hint;
file "named.ca";
};
};
view "wan" {
match-clients { 12.0.0.0/24; }; #匹配网段
zone "fql.com" IN {
type master;
file "fql.com.wan";
};
zone "." IN {
type hint;
file "named.ca";
};
};
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -a named.localhost fql.com.lan
[root@localhost named]# cp -a named.localhost fql.com.wan
[root@localhost named]# vim fql.com.lan #修改数据库配置文件
$TTL 1D
@ IN SOA master.fql.com. admin.fql.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 192.168.190.100
www A 192.168.190.88
[root@localhost named]# vim fql.com.wan
@ IN SOA master.fql.com. admin.fql.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 12.0.0.1
www A 12.0.0.8
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens36
IPADDR=12.0.0.1
#删除mac,只需要修改ens36网卡ip即可
[root@localhost named]# systemctl restart network
[root@localhost named]# systemctl restart named