配置dns服务器实现正反向解析
一、DNS正向解析
1.服务端配置
1.1关闭防火墙
[root@xx ~]# systemctl stop firewalld
[root@xx ~]# setenforce 0
1.2安装程序
[root@xx ~]# yum install bind -y
[root@xx ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.145.130; };
directory "/var/named";
allow-transfer { any; };
};
zone "openlab.com" IN {
type master;
file "named.openlab.com";
};
[root@xx ~]# vim /var/named/named.openlab.com
$TTL 1D@ IN SOA @ root.localhost. ( 2023071400 2D 4H 1D 1D ) IN NS dns.openlab.com.
dns IN A 192.168.145.130
www IN A 192.168.145.133
ftp IN A 192.168.145.100
w3 IN CNAME www
[root@xx ~]# systemctl restart named
2.客户端配置
[root@192 ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.145.130
方式一:Ping
[root@192 ~]# ping www.openlab.com
PING www.openlab.com (192.168.145.133) 56(84) bytes of data.
64 bytes from 192.168.145.133 (192.168.145.133): icmp_seq=1 ttl=64 time=0.011 ms
64 bytes from 192.168.145.133 (192.168.145.133): icmp_seq=2 ttl=64 time=0.034 ms
64 bytes from 192.168.145.133 (192.168.145.133): icmp_seq=3 ttl=64 time=0.034 ms
^C
--- www.openlab.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2018ms
rtt min/avg/max/mdev = 0.011/0.026/0.034/0.010 ms
方式二:nslookup
[root@192 ~]# nslookup www.openlab.com
Server: 192.168.145.130
Address: 192.168.145.130#53
Name: www.openlab.com
Address: 192.168.145.133
[root@192 ~]# nslookup dns.openlab.com
Server: 192.168.145.130
Address: 192.168.145.130#53
Name: dns.openlab.com
Address: 192.168.145.130
[root@192 ~]# nslookup ftp.openlab.com
Server: 192.168.145.130
Address: 192.168.145.130#53
Name: ftp.openlab.com
Address: 192.168.145.100
[root@192 ~]# nslookup w3.openlab.com
Server: 192.168.145.130
Address: 192.168.145.130#53
w3.openlab.com canonical name = www.openlab.com.
Name: www.openlab.com
Address: 192.168.145.133
二、DNS反向解析
1.服务端配置
[root@xx ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.145.130; };
directory "/var/named";
allow-transfer { any; };
};
zone "openlab.com" IN {
type master;
file "named.openlab.com";
};
zone "145.168.192.in-addr.arpa" IN {
type master;
file "named.192";
};
[root@xx ~]# vim /var/named/named.192
$TTL 1D
@ IN SOA @ root.localhost. (
2023071400
2D
4H
1D
1D )
@ IN NS dns.openlab.com.
130 IN PTR dns.openlab.com.
133 IN PTR www.openlab.com.
200 IN PTR ftp.openlab.com.
[root@xx ~]# systemctl restart named.service
2.客户端配置
[root@192 ~]# nslookup
> server 192.168.145.130
Default server: 192.168.145.130
Address: 192.168.145.130#53
> 192.168.145.100
100.145.168.192.in-addr.arpa name = ftp.openlab.com.
> 192.168.145.133
133.145.168.192.in-addr.arpa name = www.openlab.com.
> 192.168.145.130
130.145.168.192.in-addr.arpa name = dns.openlab.com.