目录
一、正向解析
1.下载DNS软件包
2.修改主配置文件
3.创建区域文件
4.配置DNS
5.测试
二、反向解析
1.修改主配置文件
2.创建区域文件
3.测试
一、正向解析
1.下载DNS软件包
[root@www ~]# yum indtall -y bind
注意:
下载软件前需要配置仓库,挂载
[root@www ~]# cd /etc/yum.repos.d/
[root@www ~]# vi rpm.repo
仓库内容:
[BaseOS]
name=BaseOS
baseurl=/mnt/BaseOS
enable=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=/mnt/AppStream
enable=1
gpgcheck=0
[root@www ~]# mkdir /mnt
[root@www ~]# mount /dev/sr0 /mnt
需要在虚拟机中勾选“已连接”,否则挂载不成功
2.修改主配置文件
[root@www ~]# vim /etc/named.conf
options {listen-on port 53 { 192.168.198.142; };directory "/var/named";
};
zone "." IN {type hint;file "named.ca";
};
zone "haha.com." IN {type master;file "named.haha";
};
zone "198.168.192.in-addr.arpa" IN {type master;file "fanxiang";
};
3.创建区域文件
[root@www ~]# vim /var/named/named.haha
$TTL 1d
@ IN SOA @ admin.haha.com. ( 20240706011111)IN NS ns.haha.com.IN MX 10 mail.haha.com.
ns IN A 192.168.198.142
mail IN A 192.168.198.38
www IN A 192.168.198.140
ftp IN CNAME www
4.配置DNS
[root@www ~]# nmcli connection modify ens160 ipv4.dns 192.168.198.2
[root@www ~]# nmcli connection up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@www ~]# nmcli device show | grep DNS
IP4.DNS[1]: 192.168.198.2
5.测试
[root@www ~]# dig -t NS haha.com ; <<>> DiG 9.16.23-RH <<>> -t NS haha.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3133
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 4;; QUESTION SECTION:
;haha.com. IN NS;; ANSWER SECTION:
haha.com. 5 IN NS ns1.mediatemple.net.
haha.com. 5 IN NS ns2.mediatemple.net.;; ADDITIONAL SECTION:
ns1.mediatemple.net. 5 IN A 97.74.100.1
ns2.mediatemple.net. 5 IN A 173.201.68.1
ns1.mediatemple.net. 5 IN AAAA 2603:5:2140::1
ns2.mediatemple.net. 5 IN AAAA 2603:5:2240::1;; Query time: 146 msec
;; SERVER: 192.168.198.2#53(192.168.198.2)
;; WHEN: Sat Jul 06 21:04:15 CST 2024
;; MSG SIZE rcvd: 165[root@www ~]# dig -t MX haha.com @192.168.198.142; <<>> DiG 9.16.23-RH <<>> -t MX haha.com @192.168.198.142
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19808
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 2;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: d58cf8c66c0968f801000000668940f6cb52c830e481d508 (good)
;; QUESTION SECTION:
;haha.com. IN MX;; ANSWER SECTION:
haha.com. 86400 IN MX 10 mail.haha.com.;; ADDITIONAL SECTION:
mail.haha.com. 86400 IN A 192.168.198.38;; Query time: 0 msec
;; SERVER: 192.168.198.142#53(192.168.198.142)
;; WHEN: Sat Jul 06 21:04:54 CST 2024
;; MSG SIZE rcvd: 102[root@www ~]# dig -t A www.haha.com; <<>> DiG 9.16.23-RH <<>> -t A www.haha.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50555
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 4;; QUESTION SECTION:
;www.haha.com. IN A;; ANSWER SECTION:
www.haha.com. 5 IN A 68.178.204.6;; AUTHORITY SECTION:
haha.com. 5 IN NS ns1.mediatemple.net.
haha.com. 5 IN NS ns2.mediatemple.net.;; ADDITIONAL SECTION:
ns1.mediatemple.net. 5 IN A 97.74.100.1
ns2.mediatemple.net. 5 IN A 173.201.68.1
ns1.mediatemple.net. 5 IN AAAA 2603:5:2140::1
ns2.mediatemple.net. 5 IN AAAA 2603:5:2240::1;; Query time: 210 msec
;; SERVER: 192.168.198.2#53(192.168.198.2)
;; WHEN: Sat Jul 06 21:06:25 CST 2024
;; MSG SIZE rcvd: 185[root@www ~]# dig -t A ftp.haha.com ; <<>> DiG 9.16.23-RH <<>> -t A ftp.haha.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16361
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 4;; QUESTION SECTION:
;ftp.haha.com. IN A;; ANSWER SECTION:
ftp.haha.com. 5 IN A 68.178.204.6;; AUTHORITY SECTION:
haha.com. 5 IN NS ns1.mediatemple.net.
haha.com. 5 IN NS ns2.mediatemple.net.;; ADDITIONAL SECTION:
ns1.mediatemple.net. 5 IN A 97.74.100.1
ns2.mediatemple.net. 5 IN A 173.201.68.1
ns1.mediatemple.net. 5 IN AAAA 2603:5:2140::1
ns2.mediatemple.net. 5 IN AAAA 2603:5:2240::1;; Query time: 146 msec
;; SERVER: 192.168.198.2#53(192.168.198.2)
;; WHEN: Sat Jul 06 21:08:47 CST 2024
;; MSG SIZE rcvd: 185
二、反向解析
1.修改主配置文件
[root@www ~]# vim /etc/named.conf
options {listen-on port 53 { 192.168.198.142; };directory "/var/named";forward only;forwarders { 61.134.1.4; };
};
zone "." IN {type hint;file "named.ca";
};
zone "haha.com." IN {type master;file "named.haha";
};
zone "198.168.192.in-addr.arpa" IN {type master;file "fanxiang";
};
2.创建区域文件
[root@www ~]# vim /var/named/named.haha
$TTL 1d
@ IN SOA @ admin.haha.com. ( 20240706011111)IN NS ns.haha.com.IN MX 10 mail.haha.com.
139 IN PTR ns.haha.com.
38 IN PTR mail.haha.com.
140 IN PTR www.haha.com.
140 IN PTR ftp.haha.com.
3.测试
[root@www ~]# dig -x 192.168.198.142; <<>> DiG 9.16.23-RH <<>> -x 192.168.198.142
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 26610
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0;; QUESTION SECTION:
;142.198.168.192.in-addr.arpa. IN PTR;; AUTHORITY SECTION:
168.192.in-addr.arpa. 5 IN SOA 168.192.in-addr.arpa. . 0 28800 7200 604800 86400;; Query time: 11 msec
;; SERVER: 192.168.198.2#53(192.168.198.2)
;; WHEN: Sat Jul 06 21:13:23 CST 2024
;; MSG SIZE rcvd: 81
[root@www ~]# dig -x 192.168.198.140; <<>> DiG 9.16.23-RH <<>> -x 192.168.198.140
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 25264
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0;; QUESTION SECTION:
;140.198.168.192.in-addr.arpa. IN PTR;; AUTHORITY SECTION:
168.192.in-addr.arpa. 5 IN SOA 168.192.in-addr.arpa. . 0 28800 7200 604800 86400;; Query time: 2014 msec
;; SERVER: 192.168.198.2#53(192.168.198.2)
;; WHEN: Sat Jul 06 21:16:42 CST 2024
;; MSG SIZE rcvd: 81[root@www ~]# dig -x 192.168.198.38; <<>> DiG 9.16.23-RH <<>> -x 192.168.198.38
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 11998
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0;; QUESTION SECTION:
;38.198.168.192.in-addr.arpa. IN PTR;; AUTHORITY SECTION:
168.192.in-addr.arpa. 5 IN SOA 168.192.in-addr.arpa. . 0 28800 7200 604800 86400;; Query time: 2019 msec
;; SERVER: 192.168.198.2#53(192.168.198.2)
;; WHEN: Sat Jul 06 21:17:22 CST 2024
;; MSG SIZE rcvd: 80