DNS服务器搭建

2022-11-01 14:32:36 浏览数 (1)

DNS服务器搭建

1.环境准备

HOSTNAME

HOSTNAME

AUTH

192.168.222.219

node1.com

master

192.168.222.220

node2.com

work

192.168.222.221

node3.com

work

192.168.222.222

node4.com

NFS,DNS

环境我是基于k8s搭建zookeeper的,懒得改

代码语言:javascript复制
[root@ nodeX]# sed -ri 's/(DNS.*)=.*/1=192.168.222.222/g' /etc/sysconfig/ifcfg-ens33
[root@ nodeX]# systemctl restart ens33
[root@ nodeX]# yum install -y bind-utils
2.DNS服务器的配置
2.1 正向解析
代码语言:javascript复制
[root@ node4]# yum install -y bind
[root@ node4]# vim /etc/named.conf    #修改两项
	listen-on port 53 { any; };
	allow-query		{ any; };
[root@ node4]# cat /etc/named.rfc1912.zone
zone "0.in-addr.arpa" IN {
        type master;
        file "named.empty";
        allow-update { none; };
};

把这5行复制到最下面4遍。

修改为

代码语言:javascript复制
zone "node1.com" IN {
        type master;
        file "node1.com.zone";
        allow-update { none; };
};

zone "node2.com" IN {
        type master;
        file "node2.com.zone";
        allow-update { none; };
};

zone "node3.com" IN {
        type master;
        file "node3.com.zone";
        allow-update { none; };
};

zone "node4.com" IN {
        type master;
        file "node4.com.zone";
        allow-update { none; };
};
代码语言:javascript复制
[root@ node4]# cd /var/named
[root@ node4]# cp -a named.localhost ./{node1.com.zone,node2.com.zone,node3.com.zone,node4.com.zone}
分别改为
[root@ node4]# cat node*.com.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
@		A	   192.168.222.219
----------------------------------------------------------
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
www     A       192.168.222.220
----------------------------------------------------------
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
www     A       192.168.222.221
----------------------------------------------------------
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
@       A       192.168.222.222
代码语言:javascript复制
# 可以使用named-checkconf /etc/named.conf /etc/named.conf (/etc/named.rfc1912.zone /etc/named.rfc1912.zone) 检测配置文件
# name-checkzone node(1-4).com.zone node(1-4).com.zone
# systemctl restart named  //重启服务,让配置生效
代码语言:javascript复制
# nslookup node1.com
Server:         192.168.222.222
Address:        192.168.222.222#53

Name:   node1.com
Address: 192.168.222.219
#其余也是一样
2.2 反向解析
代码语言:javascript复制
[root@ node4]# cat /etc/named.rpc1912.zone
zone "1.0.0.127.in-addr.arpa" IN {
        type master;
        file "named.loopback";
        allow-update { none; };
};
#还是把这5行复制4次
代码语言:javascript复制
[root@ node4]# cat /etc/named.rpc1912.zone
zone "219.222.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.222.219.zone";
        allow-update { none; };
};
zone "220.222.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.222.220.zone";
        allow-update { none; };
};
zone "221.222.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.222.221.zone";
        allow-update { none; };
};
zone "222.222.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.222.222.zone";
        allow-update { none; };
};
代码语言:javascript复制
[root@ node4]# cd /var/named
[root@ node4]# cp ./named.loopback ./192.168.222.219.zone
[root@ node4]# cp ./named.loopback ./192.168.222.220.zone
[root@ node4]# cp ./named.loopback ./192.168.222.221.zone
[root@ node4]# cp ./named.loopback ./192.168.222.222.zone
[root@ node4]# cat ./192.168.222.2*.zone
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
        PTR     node1.com.
19      PTR     node1.com.
---------------------------------------------------------
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
        PTR     node2.com.
20      PTR     node2.com.
---------------------------------------------------------
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
        PTR     node3.com.
21      PTR     node3.com.
---------------------------------------------------------
$TTL 1D
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1
        PTR     node4.com.
22      PTR     node4.com.
代码语言:javascript复制
[root@ node4]# systemctl restart named
[root@ nodeX]# nslookup 192.168.222.219
219.222.168.192.in-addr.arpa    name = node1.com.

以上。

Q.E.D.

dns

0 人点赞