centos7 DNS配置
程序员文章站
2022-05-28 10:21:08
...
服务端安装包
yum install bind
DNS 主要配置文件为:
1) /etc/named.conf # 主配置文件
2) /etc/named.rfc1912.zones # 域名配置文件
3) /var/named/ # zone 配置文件目录
修改 /etc/named.conf 文件
listen-on // 监听 IPV4 地址
listen-on-v6 // 监听 IPV6 地址
allow-query // 设置可以访问 dns 服务器的客户端
修改以下3处:
listen-on port 53 { any; };
allow-query { any; };
bindkeys-file "/etc/named.iscdlv.key";
修改完的文件如下:
options {
listen-on port 53 { 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; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
修改 /etc/named.rfc1912.zones 文件
zone "nexus.com" IN { <<<<-----正向解析
type master;
file "nexus.com.zone";
allow-update { none; };
};
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "2.98.10.in-addr.arpa" IN { <<<<-----反向解析所以IP必须写反的.我的IP是10.98.2.60
type master;
file "10.98.2.zone";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
注意文件名要跟域名配置文件中设置的 file 一致
cp /var/named/named.localhost /var/named/nexus.com.zone
编辑 nexus.com.zone 正向解析配置:
$TTL 1D
@ IN SOA @ nexus.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ NS jb <<<----域名前缀
jb A 10.98.2.60 <<----域名前缀和本机IP
编辑反向解析配置
cp /var/named/named.localhost /var/named/10.98.2.zone
$TTL 1D
@ IN SOA @ nexus.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
AAAA ::1
60 PTR jb.nexus.com. (注意60是你的IP最后4位数如 1098.2.60就是写上60)
语法检查oK 重启生效
[aaa@qq.com etc]# named-checkconf
[aaa@qq.com etc]# named-checkzone nexus.com /var/named/nexus.com.zone
zone nexus.com/IN: loaded serial 0
OK
[aaa@qq.com etc]# named-checkzone nexus.com /var/named/10.98.2.zone
zone nexus.com/IN: loaded serial 0
OK
[aaa@qq.com etc]# systemctl restart named.service
防火墙规则
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
或者直接放行UDP 53端
设置 linux 客户端安装nslookup命令
yum install bind-utils -y
linux 客户端来做测试。修改 /etc/resovled.conf 文件,添加 DNS 服务器 IP:
nameserver 10.98.2.60
或修改 /etc/sysconfig/network-scripts/ifcfg-XXXXXX 网卡文件,添加 DNS 信息,并将自定义 DNS 服务器设置为 DNS1,然后重启网络:
DNS1=10.98.2.60 # 自定义 DNS 服务器 IP
DNS2=114.114.114.114 # 公共 DNS 服务器 IP
systemctl restart network # 重启网络
重启成功后,查看 /etc/resolved.conf 文件发现自定义 DNS 更改成功。
开始正向解析测试
nslookup jb.nexus.com
Server: 10.98.2.60
Address: 10.98.2.60#53
Name: jb.nexus.com
Address: 10.98.2.60
dig jb.nexus.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> jb.nexus.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21231
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;jb.nexus.com. IN A
;; ANSWER SECTION:
jb.nexus.com. 86400 IN A 10.98.2.60
;; AUTHORITY SECTION:
nexus.com. 86400 IN NS jb.nexus.com.
;; Query time: 0 msec
;; SERVER: 10.98.2.60#53(10.98.2.60)
ping jb.nexus.com
PING jb.nexus.com (10.98.2.60) 56(84) bytes of data.
64 bytes from jb.nexus.com (10.98.2.60): icmp_seq=1 ttl=64 time=0.120 ms
64 bytes from jb.nexus.com (10.98.2.60): icmp_seq=2 ttl=64 time=0.250 ms
64 bytes from jb.nexus.com (10.98.2.60): icmp_seq=3 ttl=64 time=0.313 ms
;; WHEN: 四 7月 23 15:22:40 CST 2020
;; MSG SIZE rcvd: 71
反向解析
[aaa@qq.com ~]# nslookup 10.98.2.60
60.2.98.10.in-addr.arpa name = jb.nexus.com.
上一篇: 系统类——System类
下一篇: 深入理解System类及系统启动