125 views
Liunx-服务安装

Linux DNS配置

文章目录

曾经,同样的配置死活无法配置成功,不知道怎么的,突然就好了,记录一下,安抚我受伤的心灵!!!

安装

yum install -y bind bind-chroot bind-utils bind-devel

配置

  • /etc/named.conf 主配置文件
options {
        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

......下面不动        
  • /etc/named.rfc1912.zones 配置文件zone (本机IP为192.168.101.24,如果是云主机,使用公网IP)
# 只需要下面两个zone就行
# 正向解析
zone "wgxy2.com" IN {
        type master;
        file "wgxy2.com.zone"; # 重要的文件名称,在/var/named/ 目录下进行配置
};

# 反向解析
zone "101.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.101.arpa";# 重要的文件名称,在/var/named/ 目录下进行配置
};
  • /var/named/wgxy2.com.zone 可以拷贝该目录下的named.localhost进行修改(文件名称与上面正向解析对应)
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.wgxy2.com.
www     A       192.168.101.24
ftp     A       192.168.101.24
data    A       192.168.101.24
dns     A       192.168.101.24
  • /var/named/192.168.101.arpa 可以拷贝该目录下的named.loopback进行修改(文件名称与上面反向解析对应)
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.wgxy.com.
24      PTR     www.wgxy.com.
24      PTR     ftp.wgxy.com.
24      PTR     data.wgxy.com.
24      PTR     dns.wgxy.com.

配置完成后,需要修改文件的属主权限

chown named.named -R /var/named

测试(nslookup| host| dig)

# 正向解析设置
[root@localhost ~]# nslookup www.wgxy2.com
Server:         192.168.101.24
Address:        192.168.101.24#53

Name:   www.wgxy2.com
Address: 192.168.101.24

[root@localhost ~]# nslookup dns.wgxy2.com
Server:         192.168.101.24
Address:        192.168.101.24#53

Name:   dns.wgxy2.com
Address: 192.168.101.24

[root@localhost ~]# host www.wgxy2.com
www.wgxy2.com has address 192.168.101.24

[root@localhost ~]# dig www.wgxy2.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> www.wgxy2.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60525
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.wgxy2.com.                 IN      A

;; ANSWER SECTION:
www.wgxy2.com.          86400   IN      A       192.168.101.24

;; AUTHORITY SECTION:
wgxy2.com.              86400   IN      NS      dns.wgxy2.com.

;; ADDITIONAL SECTION:
dns.wgxy2.com.          86400   IN      A       192.168.101.24

;; Query time: 0 msec
;; SERVER: 192.168.101.24#53(192.168.101.24)
;; WHEN: 五 6月 19 00:00:38 +11 2020
;; MSG SIZE  rcvd: 92

# 反向解析设置
[root@localhost ~]# nslookup 192.168.101.24
24.101.168.192.in-addr.arpa     name = dns.wgxy.com.101.168.192.in-addr.arpa.
24.101.168.192.in-addr.arpa     name = ftp.wgxy.com.101.168.192.in-addr.arpa.
24.101.168.192.in-addr.arpa     name = www.wgxy.com.101.168.192.in-addr.arpa.
24.101.168.192.in-addr.arpa     name = data.wgxy.com.101.168.192.in-addr.arpa.

你使用局域网内的机器,配上192.168.101.24的DNS后,就可以通过域名访问改服务器了

恭喜,这样子就成功了,当然还可以做主从配置,这是最简单的

查看日志

# 查看日志,很重要,这个文件里面会有你想要的信息
tail -f /var/named/data/named.run
# 如果上面配置好了nslookup却没成功,将nameserver 192.168.101.24加入到/etc/resolv.conf中,记得一定要放在第一行!!!

#