搭建内网dns服务

安装

1
2
3
4
5
6
7
8
#安装
yum install -y bind
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
# 开机自启
systemctl enable named
# 启动
systemctl start named

配置

  1. /etc/named.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
options {
# any表示本地所有网络接口上开启53端口
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";
# 允许查询A记录的客户端列表,any表示所有
allow-query { any; };
# 设置上级提供查询解析地址的dns
forwarders { 114.114.114.114; };

recursion yes;

dnssec-enable yes;
# 关闭dns检测,使dns能够缓存外部信息到本机
dnssec-validation no;

/* Path to ISC DLV key */
bindkeys-file "/etc/named.root.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";
  1. /etc/named.rfc1912.zones

创建内网需要解析的域名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 添加该段内容
zone "hehu.com" IN {
# dns为master,即主dns
type master;
# hehu.com域名的解析文件
file "hehu.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 "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};

zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
  1. /var/named/hehu.com.zone
1
2
cd /var/named
cp named.localhost hehu.com.zone