Linux配置DNS正向和反向解析练习
基于redhat 9进行演示
一.正向解析
1.下载bind
2.编辑主配置文件
3.在工作目录下新建区域文件
4.指定解析域名IP
5.重启named并测试配置好了的域名
二.反向解析
1.编辑主配置文件,新添加区域用于反解
2.在工作目录下新建区域文件
3.重启named并测试
一.正向解析
1.下载bind
[root@redhat9-1 ~]# yum install -y bind
2.编辑主配置文件
[root@redhat9-1 ~]# vim /etc/named.conf
options {
listen-on port 53 { any; }; #将监听端口改为任意或本机IP
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 { any; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "ssll.com" IN { #指定区域
type master; #指定type类型
file "ssll.com"; #指定区域文件
};
3.在工作目录下新建区域文件
[root@redhat9-1 ~]# vim /var/named/ssll.com
$TTL 1D
@ IN SOA dns.ssll.com. test.163.com ( 0 1D 1H 1W 3H )
IN NS dns.ssll.com.
IN MX 10 mail.ssll.com.
dns.ssll.com. IN A 192.168.2.138
www.ssll.com. IN A 192.168.2.135
wwww IN CNAME www
4.指定解析域名IP
/etc/resolv.conf——DNS客户机配置文件,用于设置DNS服务器的IP地址及DNS域名,还包含了主机的域名搜索顺序
[root@redhat9-1 ~]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.2.138
5.重启named并测试配置好了的域名
[root@redhat9-1 ~]# systemctl restart named
[root@redhat9-1 ~]# nslookup www.ssll.com
Server: 192.168.2.138
Address: 192.168.2.138#53
Name: www.ssll.com
Address: 192.168.2.135
[root@redhat9-1 ~]# nslookup dns.ssll.com
Server: 192.168.2.138
Address: 192.168.2.138#53
Name: dns.ssll.com
Address: 192.168.2.138
二.反向解析
1.编辑主配置文件,新添加区域用于反解
zone "2.168.192.in-addr.arpa" IN { #网段反写并指定反解关键字
type master;
file "192.168.2";
};
2.在工作目录下新建区域文件
[root@redhat9-1 ~]# vim /var/named/192.168.2
$TTL 1D
@ IN SOA www.llss.com. admin.llss.com. ( 0 1D 1H 1W 3H )
IN NS www.llss.com.
IN MX 10 mail.llss.com.
138 IN PTR www.llss.com.
135 IN PTR dns.llss.com.
3.重启named并测试
[root@redhat9-1 ~]# systemctl restart named
[root@redhat9-1 ~]# nslookup 192.168.2.138
138.2.168.192.in-addr.arpa name = www.llss.com.
[root@redhat9-1 ~]# nslookup 192.168.2.135
135.2.168.192.in-addr.arpa name = dns.llss.com.