基于OpenEuler配置DNS服务器,能够实现正常的正反向解析rhce

操作过程,细则看注释:

[root@localhost ~]# yum install bind -y #配置环境
OS                                                                              7.9 kB/s | 1.9 kB     00:00    
everything                                                                      8.1 kB/s | 1.9 kB     00:00    
EPOL                                                                            7.8 kB/s | 1.9 kB     00:00    
update                                                                          8.3 kB/s | 1.9 kB     00:00    
update-source                                                                    10 kB/s | 2.2 kB     00:00    
Package bind-32:9.16.37-4.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

[root@localhost ~]# cat /etc/named.conf #更改配置文件 这里我直接将反向配置也已经配好
options {
	listen-on port 53 { 192.168.21.129; };
	directory 	"/var/named";
	allow-query     { any; };
	recursion yes;  //开启递归查询
	aloow-transfer {192.168.21.132;};
};
zone "baidu.com" IN {
	type master;
	file "named.baidu.com"; //正向解析资源记录文件
};

zone "21.168.192.in-addr.arpa" IN {
	type master;
	file “192”;
};

[root@localhost ~]# cat /var/named/192 # 编辑正向区域文件
$TTL 1D
@       IN      SOA     @       admin.admin.com.  (
                                        2024011501
                                        1M                                                          1M                                              
                                        3M
                                        1M )
                 NS   dns.baidu.com.
135             PTR   dns.baidu.com.               
                 NS    ns.baidu.com.                     
134             PTR   ns.baidu.com.
111             PTR   www.baidu.com.

[root@localhost ~]# cat /var/named/named.baidu.com
$TTL  1D
@		IN  SOA  @  admin.admin.com.  ( 
                     2024011400  
                      1M 
                      1M 
                      3M  
                      1D )
   		IN  NS  dns.baidu.com.
dns       	IN  A   192.168.21.129
		IN  NS  ns.baidu.com.                 
ns      	IN  A   192.168.21.132

www		IN  A   192.168.21.111
ftp	        IN  A   192.168.21.123
a	        IN  A	192.168.21.100
aaa	  	IN  CNAME   a



[root@localhost ~]# systemctl restart named # 重启服务
[root@localhost ~]# host www.baidu.com 192.168.21.129 #测试(也可用nslookup)
Using domain server:
Name: 192.168.21.129
Address: 192.168.21.129#53
Aliases: 

www.baidu.com has address 192.168.21.111

named.conf文件的详细信息:

options {
        listen-on port 53 { 192.168.21.129; };
        directory       "/var/named";
        allow-query     { any; };
        recursion yes;
        aloow-transfer {192.168.21.132;};
};
zone "baidu.com" IN {
        type master;
        file "named.baidu.com";
};

zone "21.168.192.in-addr.arpa" IN {
        type master;
        file “192”;
};

配置反向解析:

[root@localhost ~]# cat /etc/named.conf # 开启相关配置
options { //全局配置
	listen-on port 53 { 192.168.21.129; }; //监听
	directory 	"/var/named";  //数据文件主路径
	allow-query     { any; };
	recursion yes;  //开启递归
	allow-transfer { 192.168.21.132;};
};
zone "baidu.com" IN { //正向解析区域文件
	type master;
	file "named.baidu.com";
};

zone "21.168.192.in-addr.arpa" IN { //反向解析区域文件
	type master;
	file "192";
};
[root@localhost ~]# vim /var/named/named.baidu.com
[root@localhost ~]# cat /var/named/named.baidu.com 
$TTL  1D
@		IN  SOA  @  admin.admin.com.  ( 
                     2024011400  
                      1M 
                      1M 
                      3M  
                      1D )
   		IN  NS  dns.baidu.com.
dns       	IN  A   192.168.21.129
		IN  NS  ns.baidu.com.                 
ns      	IN  A   192.168.21.132

www		IN  A   192.168.21.111
ftp	        IN  A   192.168.21.123
a	        IN  A	192.168.21.100
aaa	  	IN  CNAME   a

[root@localhost ~]# vim /var/named/192 # 反向区域文件
[root@localhost ~]# cat /var/named/192
$TTL 1D
@       IN      SOA     @       admin.admin.com.  (
                                        2024011501
                                        1M   
				        1M                                              
                                        3M
                                        1M )
                 NS   dns.baidu.com.
135             PTR   dns.baidu.com.               
                 NS    ns.baidu.com.                     
134             PTR   ns.baidu.com.
111             PTR   www.baidu.com.

从服务器测试

[root@localhost ~]# hostname slave
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install bind
Last metadata expiration check: 0:22:19 ago on Fri 19 Jan 2024 12:35:26 PM CST.
Package bind-32:9.16.37-4.oe2309.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost ~]# vim /etc/named.conf
[root@localhost ~]# host www.baidu.com 192.168.21.129
Using domain server:
Name: 192.168.21.129
Address: 192.168.21.129#53
Aliases: 

www.baidu.com has address 192.168.21.111
[root@localhost ~]# host www.baidu.com 192.168.21.132
^C[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# nslookup
> server 192.168.
nslookup: couldn't get address for '192.168.': not found
[root@localhost ~]# nslookup
> server 192.168.21.129
Default server: 192.168.21.129
Address: 192.168.21.129#53
> 192.168.21.111
111.21.168.192.in-addr.arpa	name = www.baidu.com.