安装DNS服务器组件

yum install -y bind*

编辑主配置文件

vim /etc/named.conf

listen-on port 53 { any; };//修改为any
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";
recursing-file  "/var/named/data/named.recursing";
secroots-file   "/var/named/data/named.secroots";
allow-query     { any; };//修改为any

编辑区域配置文件

vim /etc/named.rfc1912.zones

//正向解析
zone "2klab.com" IN {
    type master;
    file "2klab.com.zone";
};
//反向解析
zone "25.168.192.in-addr.arpa" IN {
    type master;
    file "25.168.192.arpa";
};

编辑数据配置文件

正向解析模板为/var/named/named.locolhost
cp -a /var/named/named.locolhost /var/named/2klab.com.zone

vim /var/named/2klab.com.zone

$TTL 1D
@       IN SOA  @ rname.invalid. (
                0       ; serial
                1D      ; refresh
                1H      ; retry
                1W      ; expire
                3H )    ; minimum
        NS      dns.2klab.com.
dns.2klab.com.          IN      A       192.168.25.21
ESXi01.2klab.com.       IN      A       192.168.25.18
ESXi02.2klab.com.       IN      A       192.168.25.19
ESXi03.2klab.com.       IN      A       192.168.25.20

反向解析模板文件为/var/named/named.loopback
cp -a /var/named/named.loopback /var/named/25.168.192.arpa

vim /var/named/25.168.192.arpa

$TTL 1D
@       IN SOA  @ rname.invalid. (
                0       ; serial
                1D      ; refresh
                1H      ; retry
                1W      ; expire
                3H )    ; minimum
        NS      dns.2klab.com.
21      PTR     dns.2klab.com.
18      PTR     ESXi01.2klab.com.
19      PTR     ESXi02.2klab.com.
20      PTR     ESXi03.2klab.com.

检查配置

检查主配置文件

named-checkconf

检查数据配置文件

named-checkzone 2klab.com 2klab.com.zone(检查正向解析)
named-checkzone 25.168.192.in-addr.arpa /var/named/25.168.192.arpa(检查反向解析)

启动服务

systemctl enable named
systemctl start named

测试结果

正向解析验证

dig dns.2klab.com

输出结果:

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.3 <<>> dns.2klab.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40487
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;dns.2klab.com.                 IN      A

;; ANSWER SECTION:
dns.2klab.com.          86400   IN      A       192.168.25.21

;; AUTHORITY SECTION:
2klab.com.              86400   IN      NS      dns.2klab.com.

;; Query time: 0 msec
;; SERVER: 192.168.25.21#53(192.168.25.21)
;; WHEN: Sun Jan 17 23:43:57 CST 2021
;; MSG SIZE  rcvd: 72

反向解析验证

nslookup 192.168.25.18

输出结果

18.25.168.192.in-addr.arpa      name = ESXi01.2klab.com.
最后修改:2021 年 01 月 22 日 10 : 59 PM
如果觉得我的文章对你有用,请随意赞赏