一.配置dns服务的正反向解析
提供DNS服务的软件叫bind,服务名是named
[root@server ~]# yum install bind -y
2>对三个配置文件进行修改
- /etc/named.conf : 主配置文件,共59行,去除注释和空行之和有效行数仅30行左右,用于设置bind服务程序的运行
- /etc/named.rfc1912.zones : 区域配置文件(zone),用于==保存域名和IP地址对应关系文件的所在位置==,类似于图书目录,当需要修改域名与IP映射关系时需要在此文件中查找相关文件位置
- /var/named 目录:数据配置文件目录,该目录存储保存域名和IP地址映射关系的数据文件
/etc/named.conf:
修改11和19行即可
11 listen-on port 53 { any; };
19 allow-query { any; };
zone "openlab.com" IN {
type master;
file "openlab.com.zone";
allow-update { none; };
};
创建存储保存域名和IP地址映射关系的数据文件
[root@server named]# cp -a named.localhost openlab.com.zone ##必须加-a参数否则所属组全是root
若未加则参考下面错误进行修改即可
[root@server named]# vim openlab.com.zone
$TTL 1D
@ IN SOA ns.openlab.com. admin.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS ns.openlab.com.
ns IN A 192.168.38.128
master IN A 192.168.38.128
www IN A 192.168.38.128
bbs IN A 192.168.38.128
三种方法nmtui(图形化界面修改),nmcli(命令修改),配置文件修改(/etc/NetworkManager/system-connections/ens160.nmconnection )
[connection]
id=ens160
uuid=8eff1602-2daa-3ec2-ad30-6c5cf9f65b97
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1681106532
[ethernet]
[ipv4]
address1=192.168.38.136/24,192.168.38.2
dns=192.168.38.128;
method=manual
[ipv6]
addr-gen-mode=eui64
method=auto
[proxy]
[root@node1 ~]# nmcli connection reload
[root@node1 ~]# nmcli connection up ens160
[root@node1 ~]# nslookup www.openlab.com
Server: 192.168.38.128
Address: 192.168.38.128#53
Name: www.openlab.com
Address: 192.168.38.128
[root@node1 ~]# host -a www.openlab.com
Trying "www.openlab.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48983
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.openlab.com. IN ANY
;; ANSWER SECTION:
www.openlab.com. 86400 IN A 192.168.38.128
Received 49 bytes from 192.168.38.128#53 in 5 ms
反向解析在正向解析的基础上进行操作
配置文件的设置
现在只需要对两个文件进行配置
- /etc/named.rfc1912.zones : 区域配置文件(zone),用于==保存域名和IP地址对应关系文件的所在位置==
- /var/named 这个目录下的文件
/etc/named.rfc1912.zones
zone "38.168.192.in-addr.arpa" IN {
type master;
file "192.168.38.arpa";
allow-update { none; };
};
创建存储保存域名和IP地址映射关系的数据文件
[root@server named]# cp -a named.loopback 192.168.38.arpa ##必须加-a参数否则所属组全是root
若未加则参考下面错误进行修改即可
[root@server named]# vim openlab.com.zone
$TTL 1D
@ IN SOA ns.openlab.com. admin.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns.openlab.com.
128 IN PTR ns.openlab.com.
128 IN PTR mail.openlab.com.
128 IN PTR bbs.openlab.com.
128 IN PTR www.openlab.com.
~
[root@node1 ~]# nslookup 192.168.38.128
128.38.168.192.in-addr.arpa name = www.openlab.com.
128.38.168.192.in-addr.arpa name = mail.openlab.com.
128.38.168.192.in-addr.arpa name = ns.openlab.com.
128.38.168.192.in-addr.arpa name = bbs.openlab.com.