服务端IP | 客户端IP | 网址 |
---|---|---|
192.168.48.130 | 192.168.48.131 |
# 服务端及客户端都关闭安全软件
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# yum install bind -y
[root@server ~]# nmcli c modify ens33 ipv4.method manual ipv4.addresses 192.168.179.128/24 ipv4.gateway 192.168.179.2 ipv4.dns 114.114.114.114
[root@server ~]# nmcli c reload
[root@server ~]# nmcli c up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
# 客户端设置静态IP
[root@node1 ~]# nmcli c modify ens33 ipv4.method manual ipv4.addresses 192.168.179.129/24 ipv4.gateway 192.168.179.2 ipv4.dns 114.114.114.114
[root@node1 ~]# nmcli c reload
[root@node1 ~]# nmcli c up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/Act
注意:这里的用户端以及客户端ip都是自己的虚拟机的IP。一下是我的IP。
用户端 | 客户端 |
192.168.179.128 | 192.168.179.129 |
第一步:服务端操作,编辑bind主配置文件
[root@server ~]# vim /etc/named.conf
listen-on port 53 { any; }; # any为允许所有主机
allow-query { any; };
需要改两行。
第二步:服务端操作,编辑区域配置文件,可以选择一个模版修改局部(推荐),也可以全部清空重启写入数据
[root@server ~]# vim /etc/named.rfc1912.zones
zone "openlab.com" IN {
type master;
file "openlab.com.zone";
allow-update { none; };
};
# 第二行双引号中输入,表示管理那个区域
# 第四行双引号中输入,表示数据配置文件的名称,注意:不写路径
第三步:服务端操作,编辑数据配置文件,使用拷贝命令将模版文件(/var/named/named.localhost)复制一份在修改局部,注意:拷贝时需要加-a参数,即拷贝内容及文件属性保证文件内容一致、权限等信息不变。
[root@server ~]# 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 # -a 完整拷贝
[root@server named]# vim openlab.com.zone
$TTL 1D
openlab.com. IN SOA ns.opeblab.com. admin.openlab.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
openlab.com. IN NS ns.openlab.com.
ns.openlab.com. IN A 192.168.179.128
www.openlab.com. IN A 192.168.179.128
ftp.openlab.com. IN A 192.168.179.128
bbs.openlab.com. IN A 192.168.179.128
www1.openlab.com. IN CNAME www.openlab.com.
第四步:服务端重启服务
[root@server named]# systemctl restart named
[root@node1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
dns=192.168.179.128;
[root@node1 ~]# nmcli c reload
[root@node1 ~]# nmcli c up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)
[root@node1 ~]# nslookup www.openlab.com
Server: 192.168.179.128
Address: 192.168.179.128#53
Name: www.openlab.com
Address: 192.168.179.128
[root@node1 ~]# nslookup
> bbs.openlab.com
Server: 192.168.179.128
Address: 192.168.179.128#53
Name: bbs.openlab.com
Address: 192.168.179.128
>
[root@node1 ~]# dig www.opnelab.com
; <<>> DiG 9.16.23-RH <<>> www.opnelab.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 32112
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 518104d477dc5c0801000000647eb0d120c077e2842cd3b4 (good)
;; QUESTION SECTION:
;www.opnelab.com. IN A
;; AUTHORITY SECTION:
com. 863 IN SOA a.gtld-servers.net. nstld.verisign-grs.com. 1686024343 1800 900 604800 86400
;; Query time: 0 msec
;; SERVER: 192.168.179.128#53(192.168.179.128)
;; WHEN: Tue Jun 06 12:06:41 CST 2023
;; MSG SIZE rcvd: 151
[root@node1 ~]# nslookup www1.openlab.com
Server: 192.168.179.128
Address: 192.168.179.128#53
www1.openlab.com canonical name = www.openlab.com.
Name: www.openlab.com
Address: 192.168.179.128
基于上例的正向解析
服务端IP | 客户端IP | 网址 |
---|---|---|
192.168.179.128 | 192.168.179.129 |
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
服务端安装bind软件
[root@server ~]# yum install bind -y
服务端配置静态IP
[root@server ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.48.130/24 ipv4.gateway 192.168.48.2 ipv4.dns 114.114.114.114
[root@server ~]# nmcli c reload
[root@server ~]# nmcli c up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
客户端设置静态IP
[root@node1 ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.48.131/24 ipv4.gateway 192.168.48.2 ipv4.dns 192.168.48.130
[root@node1 ~]# nmcli c reload
[root@node1 ~]# nmcli c up ens160
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/Act
第一步:服务端操作,编辑主配置文件
[root@server ~]# vim /etc/named.conf
listen-on port 53 { any; };
allow-query { 192.168.48.131; };
[root@server named]# vim /etc/named.rfc1912.zones
zone "48.168.192.in-addr.arpa" IN {
type master;
file "192.168.48.arpa";
allow-update { none; };
};
第三步:服务端操作,编辑数据配置文件,复制一份反向解析模(/var/named/named.loopback),复制时需要加-a 参数,在修改局部即可
[root@server ~]# cd /var/named
[root@server named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@server named]# cp -a named.loopback 192.168.179.arpa
[root@server named]# vim 192.168.179.arpa
$TTL 1D
@ IN SOA ns.openlab.com. jenny.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS ns.openlab.com.
ns.openlab.com. IN A 192.168.179.128
130 IN PTR ns.openlab.com.
130 IN PTR www.openlab.com.
130 IN PTR ftp.openlab.com.
第四步:重启服务
[root@server named]# systemctl restart named
[root@node1 ~]# nslookup 192.168.179.128
128.179.168.192.in-addr.arpa name = www.openlab.com.
128.179.168.192.in-addr.arpa name = ftp.openlab.com.
128.179.168.192.in-addr.arpa name = ns.openlab.com.