dns的正反向解析

  • Post author:
  • Post category:其他


一,正向解析

1.关闭selinux和防火墙

[root@A ~]# setenforce 0
[root@A ~]# systemctl stop firewalld

2.安装DNS软件


[root@A ~]# yum install bind -y

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

[root@A ~]# vim /etc/named.conf
options {
        listen-on port 53 { 192.168.90.132; };  //允许的主机访问
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
	    allow-query     { any; };   //允许任何客户机可以访问dns服务
	    
	logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
	};

	zone "ztl.com" IN {
        type master;
        file "named.ztl.com";
	};

	include "/etc/named.rfc1912.zones";
	include "/etc/named.root.key";

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

[root@A ~]# vim /var/named/named.ztl.com
	$TTL 1D
	ztl.com.  IN  SOA ns.ztl.com. admin.qq.com (
                                 	2023050500
                                 	1D
                                 	3H
                                 	12H
                                 	2D)

	ztl.com.  IN  NS  ns.ztl.com.
	ns        IN  A   192.168.90.132
	www       IN  A   192.168.90.111
	ftp       IN  A   192.168.90.121
	http      IN  CNAME www

5.重启服务

[root@A ~]# systemctl start named

6.客户端测试

客户端
[root@B ~]# vim /etc/resolv.conf
	# Generated by NetworkManager
	search localdomain
	nameserver 192.168.90.132
[root@B ~]# nslookup
> server 192.168.90.132
Default server: 192.168.90.132
Address: 192.168.90.132#53
> www.ztl.com
Server:		192.168.90.132
Address:	192.168.90.132#53

Name:	www.ztl.com
Address: 192.168.90.111
> http.ztl.com
Server:		192.168.90.132
Address:	192.168.90.132#53

http.ztl.com	canonical name = www.ztl.com.
Name:	www.ztl.com
Address: 192.168.90.111

二.反向解析

1.服务端操作

[root@A ~]# vim /etc/named.conf
zone "90.168.192.in-addr.arpa" IN { 
    type master;
    file "named.192.168.90";
};

2.反向区域文件

[root@A ~]# vim /var/named/named.192.168.90
$TTL 1D
@ IN SOA ns.baidu.com. admin.baidu.com. ( 0 1D 1H 1W 3H )
	IN NS ns.baidu.com.
128 IN PTR ns.baidu.com.
128 IN PTR www.baidu.com.
128 IN PTR mail.baidu.com.
128 IN PTR ftp.baidu.com.

3.客户端测试

[root@srever ~]# nslookup 
> 192.168.90.128
128.90.168.192.in-addr.arpa	name = ns.openlab.com.
128.90.168.192.in-addr.arpa	name = www.openlab.com.
128.90.168.192.in-addr.arpa	name = mail.openlab.com.
128.90.168.192.in-addr.arpa	name = ftp.openlab.com.
> 



版权声明:本文为Ztl123321原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。