配置DNS服务的正反向解析

服务端与客户端关闭防火墙

[root@server ~]# setenforce 0
setenforce: SELinux is disabled
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld

服务端安装bind

[root@server ~]# yum install bind -y
Last metadata expiration check: 0:41:39 ago on 2024年03月09日 星期六 11时13分54秒.
Dependencies resolved.
==========================================================================
 Package                       Arch    Version                  Repo
                                                                     Size
==========================================================================
Installing:
 bind                          x86_64  32:9.16.23-20.oe2203sp3  OS  489 k
Installing dependencies:
 bind-dnssec-doc               noarch  32:9.16.23-20.oe2203sp3  OS   47 k
 checkpolicy                   x86_64  3.3-3.oe2203sp3          OS  289 k
 policycoreutils-python-utils  noarch  3.3-8.oe2203sp3          OS   24 k
 python3-IPy                   noarch  1.01-2.oe2203sp3         OS   36 k
 python3-audit                 x86_64  1:3.0.1-11.oe2203sp3     OS   74 k
 python3-bind                  noarch  32:9.16.23-20.oe2203sp3  OS   65 k
 python3-libselinux            x86_64  3.3-5.oe2203sp3          OS  163 k
 python3-libsemanage           x86_64  3.3-5.oe2203sp3          OS   69 k
 python3-ply                   noarch  3.11-3.oe2203sp3         OS   89 k
 python3-policycoreutils       noarch  3.3-8.oe2203sp3          OS  1.7 M
 python3-setools               x86_64  4.4.0-5.oe2203sp3        OS  536 k
Installing weak dependencies:
 bind-dnssec-utils             x86_64  32:9.16.23-20.oe2203sp3  OS   98 k

Transaction Summary
==========================================================================
Install  13 Packages

Total download size: 3.6 M
Installed size: 10 M
Downloading Packages:
[MIRROR] bind-9.16.23-20.oe2203sp3.x86_64.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.163.com/openeuler/openEuler-22.03-LTS-SP3/OS/x86_64/Packages/bind-9.16.23-20.oe2203sp3.x86_64.rpm [SSL certificate problem: certificate is not yet valid]
[MIRROR] bind-dnssec-utils-9.16.23-20.oe2203sp3.x86_64.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.163.com/openeuler/openEuler-22.03-LTS-SP3/OS/x86_64/Packages/bind-dnssec-utils-9.16.23-20.oe2203sp3.x86_64.rpm [SSL certificate problem: certificate is not yet valid]
(1/13): bind-dnssec-utils-9.16.23-20.oe22 213 kB/s |  98 kB     00:00    
[MIRROR] checkpolicy-3.3-3.oe2203sp3.x86_64.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.163.com/openeuler/openEuler-22.03-LTS-SP3/OS/x86_64/Packages/checkpolicy-3.3-3.oe2203sp3.x86_64.rpm [SSL certificate problem: certificate is not yet valid]
(2/13): bind-9.16.23-20.oe2203sp3.x86_64. 657 kB/s | 489 kB     00:00    
(3/13): policycoreutils-python-utils-3.3- 459 kB/s |  24 kB     00:00    
(4/13): checkpolicy-3.3-3.oe2203sp3.x86_6 601 kB/s | 289 kB     00:00    
(5/13): python3-IPy-1.01-2.oe2203sp3.noar 206 kB/s |  36 kB     00:00    
(6/13): python3-audit-3.0.1-11.oe2203sp3. 422 kB/s |  74 kB     00:00    
[MIRROR] bind-dnssec-doc-9.16.23-20.oe2203sp3.noarch.rpm: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.163.com/openeuler/openEuler-22.03-LTS-SP3/OS/x86_64/Packages/bind-dnssec-doc-9.16.23-20.oe2203sp3.noarch.rpm [SSL certificate problem: certificate is not yet valid]
(7/13): python3-bind-9.16.23-20.oe2203sp3 252 kB/s |  65 kB     00:00    
(8/13): bind-dnssec-doc-9.16.23-20.oe2203  31 kB/s |  47 kB     00:01    
(9/13): python3-libsemanage-3.3-5.oe2203s 183 kB/s |  69 kB     00:00    
(10/13): python3-libselinux-3.3-5.oe2203s 294 kB/s | 163 kB     00:00    
(11/13): python3-ply-3.11-3.oe2203sp3.noa 260 kB/s |  89 kB     00:00    
(12/13): python3-setools-4.4.0-5.oe2203sp 433 kB/s | 536 kB     00:01    
(13/13): python3-policycoreutils-3.3-8.oe 419 kB/s | 1.7 MB     00:04    
--------------------------------------------------------------------------
Total                                     604 kB/s | 3.6 MB     00:06     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                  1/1 
  Installing       : python3-libselinux-3.3-5.oe2203sp3.x86_64       1/13 
  Installing       : python3-libsemanage-3.3-5.oe2203sp3.x86_64      2/13 
  Installing       : python3-setools-4.4.0-5.oe2203sp3.x86_64        3/13 
  Installing       : python3-ply-3.11-3.oe2203sp3.noarch             4/13 
  Installing       : python3-bind-32:9.16.23-20.oe2203sp3.noarch     5/13 
  Installing       : python3-audit-1:3.0.1-11.oe2203sp3.x86_64       6/13 
  Installing       : python3-IPy-1.01-2.oe2203sp3.noarch             7/13 
  Running scriptlet: checkpolicy-3.3-3.oe2203sp3.x86_64              8/13 
  Installing       : checkpolicy-3.3-3.oe2203sp3.x86_64              8/13 
  Running scriptlet: checkpolicy-3.3-3.oe2203sp3.x86_64              8/13 
  Installing       : python3-policycoreutils-3.3-8.oe2203sp3.noar    9/13 
  Installing       : policycoreutils-python-utils-3.3-8.oe2203sp3   10/13 
  Installing       : bind-dnssec-doc-32:9.16.23-20.oe2203sp3.noar   11/13 
  Installing       : bind-dnssec-utils-32:9.16.23-20.oe2203sp3.x8   12/13 
  Running scriptlet: bind-32:9.16.23-20.oe2203sp3.x86_64            13/13 
  Installing       : bind-32:9.16.23-20.oe2203sp3.x86_64            13/13 
  Running scriptlet: bind-32:9.16.23-20.oe2203sp3.x86_64            13/13 
  Verifying        : bind-32:9.16.23-20.oe2203sp3.x86_64             1/13 
  Verifying        : bind-dnssec-doc-32:9.16.23-20.oe2203sp3.noar    2/13 
  Verifying        : bind-dnssec-utils-32:9.16.23-20.oe2203sp3.x8    3/13 
  Verifying        : checkpolicy-3.3-3.oe2203sp3.x86_64              4/13 
  Verifying        : policycoreutils-python-utils-3.3-8.oe2203sp3    5/13 
  Verifying        : python3-IPy-1.01-2.oe2203sp3.noarch             6/13 
  Verifying        : python3-audit-1:3.0.1-11.oe2203sp3.x86_64       7/13 
  Verifying        : python3-bind-32:9.16.23-20.oe2203sp3.noarch     8/13 
  Verifying        : python3-libselinux-3.3-5.oe2203sp3.x86_64       9/13 
  Verifying        : python3-libsemanage-3.3-5.oe2203sp3.x86_64     10/13 
  Verifying        : python3-ply-3.11-3.oe2203sp3.noarch            11/13 
  Verifying        : python3-policycoreutils-3.3-8.oe2203sp3.noar   12/13 
  Verifying        : python3-setools-4.4.0-5.oe2203sp3.x86_64       13/13 

Installed:
  bind-32:9.16.23-20.oe2203sp3.x86_64                                     
  bind-dnssec-doc-32:9.16.23-20.oe2203sp3.noarch                          
  bind-dnssec-utils-32:9.16.23-20.oe2203sp3.x86_64                        
  checkpolicy-3.3-3.oe2203sp3.x86_64                                      
  policycoreutils-python-utils-3.3-8.oe2203sp3.noarch                     
  python3-IPy-1.01-2.oe2203sp3.noarch                                     
  python3-audit-1:3.0.1-11.oe2203sp3.x86_64                               
  python3-bind-32:9.16.23-20.oe2203sp3.noarch                             
  python3-libselinux-3.3-5.oe2203sp3.x86_64                               
  python3-libsemanage-3.3-5.oe2203sp3.x86_64                              
  python3-ply-3.11-3.oe2203sp3.noarch                                     
  python3-policycoreutils-3.3-8.oe2203sp3.noarch                          
  python3-setools-4.4.0-5.oe2203sp3.x86_64                                

Complete!

服务端与客户端设置静态IP

[root@node ~]# nmcli c modify ens32  ipv4.method manual ipv4.addresses 192.168.205.138/24 ipv4.gateway 192.168.205.2 ipv4.dns 114.114.114.114
[root@node ~]# nmcli c reload
[root@node ~]# nmcli c up ens32

DNS配置

服务端操作,编辑bind主配置文件

[root@server ~]# vim  /etc/named.conf 
# 需改2行
       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
[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.205.137
www.openlab.com.        IN      A       192.168.205.137
ftp.openlab.com.        IN      A       192.168.205.137
bbs.openlab.com.        IN      A       192.168.205.137
www1.openlab.com.       IN      CNAME   www.openlab.com.

服务端重启服务

[root@Server named]# systemctl restart named

测试

定义客户端,将客户端的dns修改为服务端的IP地址

[root@node1 ~]# vim  /etc/sysconfig/network-scripts/ifcfg-ens32 
dns=192.168.48.130;    

[root@node ~]# nmcli c reload 
[root@node ~]# nmcli c up ens32
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)

# 定位客户端测试

[root@node ~]# nslookup www.openlab.com
Server:        192.168.205.137
Address:    192.168.205.137#53

Name:    www.openlab.com
Address: 192.168.205.137

[root@node ~]# nslookup        # 进入交互模式
> bbs.openlab.com
Server:        192.168.205.137
Address:    192.168.205.137#53

Name:    bbs.openlab.com
Address: 192.168.205.137
>                                          # ctrl+d退出
[root@node ~]# dig www.openlab.com

; <<>> DiG 9.16.23 <<>> www.openlab.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48463
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: ff4e9869598fb20a0100000065ec0536ad9ca488cffd368c (good)
;; QUESTION SECTION:
;www.openlab.com.        IN    A

;; ANSWER SECTION:
www.openlab.com.    86400    IN    A    192.168.205.137

;; Query time: 2 msec
;; SERVER: 192.168.205.137#53(192.168.205.137)
;; WHEN: Sat Mar 09 17:42:29 CST 2024
;; MSG SIZE  rcvd: 88

[root@node ~]# nslookup www1.openlab.com
Server:        192.168.205.137
Address:    192.168.205.137#53

www1.openlab.com    canonical name = www.openlab.com.
Name:    www.openlab.com
Address: 192.168.205.137

反向解析

与正向解析相似 所以步骤不一一写出

这里写DNS的配置

服务端操作,编辑主配置文件

[root@Server ~]# vim /etc/named.conf

options {
        listen-on port 53 { any; };       # any为允许所有主机
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        secroots-file   "/var/named/data/named.secroots";
        recursing-file  "/var/named/data/named.recursing";
        allow-query     { 192.168.205.138; };

服务端操作,编辑区域配置文件,添加反向解析记录,注意:区域名称中IP地址反向书写,只需书写网段号

[root@server named]# vim  /etc/named.rfc1912.zones

zone "205.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.205.arpa";
        allow-update { none; };
};

服务端操作,编辑数据配置文件

[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.205.arpa
[root@Server named]# vim  192.168.205.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.48.130
130                             IN      PTR     ns.openlab.com.
130                             IN      PTR     www.openlab.com.
130                             IN      PTR     ftp.openlab.com.

最后重启服务 在客户端测试就好啦。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值