1、配置dns的正向解析
关闭SElinux,关闭防火墙
[root@server ~]# setenforce 0
setenforce: SELinux is disabled
[root@server ~]# systemctl stop firewalld
安装bind
[root@server ~]# yum install bind -y
定位服务端,配置dns主配置文件
[root@server named]# vim /etc/named.conf
服务端编辑区域配置文件
[root@server named]# vim /etc/named.rfc1912.zones
编辑数据配置文件,使用cp -a命令完全拷贝一份正向解析模版(named.localhost)再修改其局部
[root@server named]# cd /var/named/
[root@server named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@server named]# cp -a named.localhost openlab.com.zone
[root@server named]# vim openlab.com.zone
服务端操作,重启服务
[root@server named]# systemctl start named
测试,将客户端的网卡配置文件中的DNS解析地址修改为服务端的IP地址,以后客户端的dns解析申请会交给服务端来完成。
[root@node1 ~]# vim /etc/NetworkManager/system-connections/ens160.nmconnection
[root@node1 ~]# nmcli connection reload # 重载配置文件
[root@node1 ~]# nmcli connection up ens160 # 激活连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
测试:
[root@node1 ~]# nslookup # 进入交互模式进行测试
> www.openlab.com
Server: 192.168.136.128
Address: 192.168.136.128#53Name: www.openlab.com
Address: 192.168.136.128
> ftp.openlab.com
Server: 192.168.136.128
Address: 192.168.136.128#53Name: ftp.openlab.com
Address: 192.168.136.128
> www1.openlab.com
Server: 192.168.136.128
Address: 192.168.136.128#53www1.openlab.com canonical name = www.openlab.com.
Name: www.openlab.com
Address: 192.168.136.128[root@node1 ~]# nslookup bbs.openlab.com # 命令模式
Server: 192.168.136.128
Address: 192.168.136.128#53Name: bbs.openlab.com
Address: 192.168.136.128# 或者使用下列方法测试
[root@node1 ~]# host www.openlab.com[root@node1 ~]# dig @192.168.136.128 www.openlab.com
2、反向解析
服务端操作,基于上例,继续完成,主配置文件按照上例设置不变,编辑区域配置文件,选择一个反向解析模版进行修改。
[root@server ~]# vim /etc/named.rfc1912.zones
zone "136.168.192.in-addr.arpa" IN {
type master;
file "192.168.136.arpa";
allow-update { none; };
};
服务端操作,编辑数据配置文件,复制一份反向解析模版(named.loopback),在修改局部即可
[root@server ~]# cd /var/named/
[root@server named]# cp -a named.loopback 192.168.136.arpa
[root@server named]# vim 192.168.136.arpa
$TTL 1D
@ IN SOA ns.openlab.com. jenny.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns.openlab.com.
130 IN PTR ns.openlab.com.130 IN PTR www.openlab.com.
130 IN PTR bbs.openlab.com.
130 IN PTR ftp.openlab.com.
服务端重启服务
[root@server named]# systemctl restart named
客户端操作,测试
[root@node1 ~]# nslookup
> www.openlab.com
Server: 192.168.136.128
Address: 192.168.136.128#53Name: www.openlab.com
Address: 192.168.136.128
> 192.168.136.128
128.136.168.192.in-addr.arpa name = ftp.openlab.com.
128.136.168.192.in-addr.arpa name = ns.openlab.com.
128.136.168.192.in-addr.arpa name = www.openlab.com.
128.136.168.192.in-addr.arpa name = bbs.openlab.com.