环境和目标
在我的测试 KVM 实验室中,我有一个虚拟网络172.16.50/24
,在这个网络中我有 2 个运行 Bind 9 和 ISC DHCP 服务器的 Centos 7 VM:
- DNS 主服务器:
controller.wsvirt.home (172.16.50.2)
- 从属 DNS:
controller2.wsvirt.home (172.16.50.3)
网络中的所有客户端都是 Linux VM,它们都从 DHCP 服务器获取网络配置。该服务器动态更新 DNS 区域。
Bind 9 是区域的权威服务器wsvirt.home
。
在实验室环境中,我测试了必须在我们的商务办公网络中实施的场景。在业务环境中,我应该创建一个 AD 域来为 Windows 客户端提供服务,为此,我们决定使用 Samba 4 作为 DC。我已经为 Centos 7 构建了一个 Samba 服务器,并从源代码中支持 Heimdal Kerberos。
对于 AD,我分配了子网172.16.50.192/26
并指定了ad.wsvirt.home
域。
AD DC 是运行 Samba 4、Bind 9 和 ISC DHCP 服务器的 Centos 7 VM。Samba 使用 BIND_DLZ 作为 DNS 后端。AD 控制器具有addc1.ad.wsvirt.home
域名和IP 172.16.50.193
。
所有 Windows AD 客户端都从在 AD DC 上运行的 DHCP 服务器获取 IP,该服务器动态更新绑定 DLZ 区域。
在实际工作的物理环境中,来自两个网络的所有客户端PC都应连接到一个广播域。
为了满足要求,我将正向ad.wsvirt.home
和反向172.16.50.192/26
DNS 区域的权限从服务器上的 Bind 委托controller.wsvirt.home
给 AD 控制器,addc1.ad.wsvirt.home
以便RFC 2317。
# 问题 #
除了一件事之外,一切都运行正常。当我通过 AD DC 测试委派反向区域的反向查找时,结果看起来不错,因此 Windows AD 客户端可以解析两个域中的所有反向域名。:
$ dig -x 172.16.50.193 @addc1.ad.wsvirt.home
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> -x 172.16.50.193 @addc1.ad.wsvirt.home
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43507
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;193.50.16.172.in-addr.arpa. IN PTR
;; ANSWER SECTION:
193.50.16.172.in-addr.arpa. 86400 IN CNAME 193.50.16.172.ddns.
193.50.16.172.ddns. 900 IN PTR addc1.ad.wsvirt.home.
;; Query time: 7 msec
;; SERVER: 172.16.50.193#53(172.16.50.193)
;; WHEN: Mon Mar 30 21:05:12 IDT 2020
;; MSG SIZE rcvd: 121
但是,当我将请求路由到 DNS 服务器时,controller.wsvirt.home
它不会解析域中的任何反向名称ad.wsvirt.home
,因此 Linux 客户端也无法查找任何反向名称:
$ dig -x 172.16.50.193 @controller.wsvirt.home
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> -x 172.16.50.193 @controller.wsvirt.home
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 48825
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;193.50.16.172.in-addr.arpa. IN PTR
;; ANSWER SECTION:
193.50.16.172.in-addr.arpa. 86400 IN CNAME 193.50.16.172.ddns.
;; AUTHORITY SECTION:
. 8133 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2020033001 1800 900 604800 86400
;; Query time: 0 msec
;; SERVER: 172.16.50.2#53(172.16.50.2)
;; WHEN: Mon Mar 30 21:49:41 IDT 2020
;; MSG SIZE rcvd: 162
我需要域中的 Linux 客户端wsvirt.home
能够解析域中的反向域名ad.wsvirt.home
。这可能吗?
配置
为了更准确,我在这里放了两个服务器的配置文件
服务器控制器.wsvirt.home
/etc/named.conf
acl local { 172.16.50.0/24; 127.0.0.1; };
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
include "/etc/rndc.key";
server 172.16.50.3 {
keys { "rndc-key"; };
};
...
options {
listen-on port 53 { local; };
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 { local; };
allow-transfer { none; };
notify no;
forwarders { 8.8.8.8; 8.8.4.4; };
forward only;
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";
};
zone "." IN {
type hint;
file "named.ca";
};
zone "wsvirt.home" IN {
type master;
file "wsvirt.home.db";
allow-update { key "rndc-key"; };
allow-transfer { key "rndc-key"; };
notify yes;
forwarders {};
};
zone "50.16.172.in-addr.arpa" IN {
type master;
file "50.16.172.db";
allow-update { key "rndc-key"; };
allow-transfer { key "rndc-key"; };
notify yes;
};
/var/named/50.16.172.db
$ORIGIN .
$TTL 86400 ; 1 day
50.16.172.in-addr.arpa IN SOA controller.wsvirt.home. root.wsvirt.home. (
153 ; serial
3600 ; refresh (1 hour)
1800 ; retry (30 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS controller.wsvirt.home.
NS controller2.wsvirt.home.
$ORIGIN 50.16.172.in-addr.arpa.
2 PTR controller.wsvirt.home.
$TTL 86400 ; 1 day
3 PTR controller2.wsvirt.home.
...
;
50.16.172.ddns. IN NS addc1.ad.wsvirt.home.
$GENERATE 193-254 $ IN CNAME $.50.16.172.ddns.
/etc/dhcp/dhcpd.conf
include "/etc/rndc.key";
default-lease-time 600;
max-lease-time 7200;
authoritative;
ddns-update-style interim;
class "windows" {
match if substring (option vendor-class-identifier, 0, 8) = "MSFT 5.0";
}
subnet 172.16.50.0 netmask 255.255.255.0 {
log (info, concat("Vendor Class ID (60): ", option vendor-class-identifier));
log (info, concat("DHCP Client ID (61): ", option dhcp-client-identifier));
log (info, concat("User Class ID (77): ", option user-class));
option domain-name-servers 172.16.50.2, 172.16.50.3;
option ntp-servers 172.16.50.2;
option routers 172.16.50.1;
option broadcast-address 172.16.50.255;
default-lease-time 600;
max-lease-time 7200;
option ip-forwarding off;
ignore client-updates;
option domain-name "wsvirt.home";
option domain-search "wsvirt.home";
option netbios-scope "";
option netbios-node-type 8;
option netbios-name-servers 172.16.50.2;
option netbios-dd-server 172.16.50.2;
ddns-updates on;
ddns-domainname "wsvirt.home.";
ddns-rev-domainname "in-addr.arpa.";
pool {
range 172.16.50.21 172.16.50.190;
deny members of "windows";
}
zone wsvirt.home {
primary 172.16.50.2;
key "rndc-key";
}
zone 50.16.172.in-addr.arpa {
primary 172.16.50.2;
key "rndc-key";
}
}
广告 DC addc1.ad.wsvirt.home
/etc/named.conf
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; };
forwarders { 172.16.50.2; 172.16.50.3; };
forward only;
recursion yes;
dnssec-enable no;
dnssec-validation no;
bindkeys-file "/etc/named.root.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
tkey-gssapi-keytab "/var/lib/samba/private/dns.keytab";
minimal-responses yes;
};
...
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/rndc.key";
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
include "/var/lib/samba/bind-dns/named.conf";
/etc/dhcp/dhcpd.conf
include "/etc/rndc.key";
default-lease-time 600;
max-lease-time 7200;
min-secs 5;
authoritative;
ddns-update-style none;
class "others" {
match if substring (option vendor-class-identifier, 0, 8) != "MSFT 5.0";
}
subnet 172.16.50.192 netmask 255.255.255.192 {
log (info, concat("Vendor Class ID (60): ", option vendor-class-identifier));
log (info, concat("DHCP Client ID (61): ", option dhcp-client-identifier));
log (info, concat("User Class ID (77): ", option user-class));
option routers 172.16.50.1;
option broadcast-address 172.16.50.255;
default-lease-time 600;
max-lease-time 7200;
option ip-forwarding off;
ignore client-updates;
option ntp-servers 172.16.50.193;
option domain-name-servers 172.16.50.193;
option domain-name "ad.wsvirt.home";
option domain-search "ad.wsvirt.home";
option netbios-name-servers 172.16.50.193;
option netbios-dd-server 172.16.50.193;
option netbios-scope "";
option netbios-node-type 8;
ddns-rev-domainname "ddns";
pool {
range 172.16.50.210 172.16.50.254;
deny members of "others";
}
}
on commit {
set noname = concat("dhcp-", binary-to-ascii(10, 8, "-", leased-address));
set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
set ClientDHCID = concat (
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2)
);
set ClientName = pick-first-value(option host-name, config-option-host-name, client-name, noname);
log(concat("Commit: IP: ", ClientIP, " DHCID: ", ClientDHCID, " Name: ", ClientName));
execute("/usr/local/sbin/dhcp-dyndns.sh", "add", ClientIP, ClientDHCID, ClientName);
}
on release {
set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
set ClientDHCID = concat (
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2)
);
log(concat("Release: IP: ", ClientIP));
execute("/usr/local/sbin/dhcp-dyndns.sh", "delete", ClientIP, ClientDHCID);
}
on expiry {
set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
log(concat("Expired: IP: ", ClientIP));
execute("/usr/local/sbin/dhcp-dyndns.sh", "delete", ClientIP, "", "0");
}
AD DC 上的 DLZ 反向区域 50.16.172.ddns
$ samba-tool dns query localhost 50.16.172.ddns @ ALL
Password for [[email protected]]:
Name=, Records=2, Children=0
SOA: serial=3, refresh=900, retry=600, expire=86400, minttl=3600, ns=addc1.ad.wsvirt.home., email=hostmaster.ad.wsvirt.home. (flags=600000f0, serial=3, ttl=3600)
NS: addc1.ad.wsvirt.home. (flags=600000f0, serial=1, ttl=3600)
Name=193, Records=1, Children=0
PTR: addc1.ad.wsvirt.home (flags=f0, serial=3, ttl=900)
Name=230, Records=1, Children=0
PTR: winxp-1.ad.wsvirt.home (flags=f0, serial=3, ttl=3600)
答案1
得到不PTR
一样的答案是正常的,因为controller.wsvirt.home.
不是一个权威性这两个区域的名称服务器。flags: aa
称这是权威答案,但对 来说并非如此193.50.16.172.ddns. IN PTR
。因此,无法发送此权威答案。
这实际上不是一个问题,因为这只会导致对 的另一次查询193.50.16.172.ddns. IN PTR
,然后可以递归地回答。客户端应该知道在有CNAME
答案的情况下自动执行此操作。
关于这一点,另一个问题,因为只有addc1.ad.wsvirt.home.
区域50.16.172.ddns.
;你会得到NXDOMAIN
答案:
dig 193.50.16.172.ddns. PTR @controller.wsvirt.home
被controller.wsvirt.home.
配置为递归 ( recursion yes;
),但它不知道这些地址可以在 上找到addc1.ad.wsvirt.home.
。因此,它尝试将它们解析为其他所有内容:来自forwarders { 8.8.8.8; 8.8.4.4; };
... 并失败。
您可以将 添加为addc1.ad.wsvirt.home.
的转发器:50.16.172.ddns.
controller.wsvirt.home.
zone "50.16.172.ddns." {
type forward;
forwarders { 172.16.50.193; };
};
最后, 的区域$ORIGIN 50.16.172.in-addr.arpa.
只能委托对其自己的子域的控制,而不能委托对完全不相关的 的控制50.16.172.ddns.
。
如果您确实仍想发送PTR
相同的响应,则需要50.16.172.ddns.
通过添加slave
区域(而不是区域forward
)使该域具有权威性,例如
zone "50.16.172.ddns." {
type slave;
file "50.16.172.ddns.db";
masters { 172.16.50.193; };
};
主服务器(addc1.ad.wsvirt.home.
)需要意识到这一点,并允许从 进行区域传输controller.wsvirt.home.
(并且controller2.wsvirt.home
,如果它应该采取类似行动):
options {
. . .
allow-transfer { 172.16.50.2; 172.16.50.3; };
}
答案2
如果您要使用我的脚本,请正确使用它;-)
在 DC 上运行 Bind9 和 isc-dhcp,而不是在其他地方。请参见此处:
https://wiki.samba.org/index.php/Setting_up_a_BIND_DNS_Server
https://wiki.samba.org/index.php/Configure_DHCP_to_update_DNS_records_with_BIND9
您的主要问题之一是您尝试将反向区域存储在“平面文件”中,而 bind9_dlz 不适用于平面文件。
答案3
根据 Esa Jokinen 的建议我做了以下事情:
在控制器.wsvirt.home在/etc/named.conf
我为 创建了一个区域部分50.16.172.ddns
。
zone "50.16.172.ddns." {
type slave;
file "slaves/50.16.172.ddns.db";
masters { 172.16.50.193; };
};
在区域文件中,/var/named/50.16.172.db
我注释掉了委派区域的行50.16.172.ddns
:
;50.16.172.ddns. IN NS addc1.ad.wsvirt.home.
;$GENERATE 193-254 $ IN CNAME $.50.16.172.ddns.
在添加 c1.ad.wsvirt.home。在里面/etc/named.conf
:
options {
. . .
allow-transfer { 172.16.50.2; 172.16.50.3; };
}
因此,我拥有该区域的权限50.16.172.ddns
,但是反向名称根本没有解析:
dig -x 172.16.50.193 @addc1.ad.wsvirt.home
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> -x 172.16.50.193 @addc1.ad.wsvirt.home
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 30147
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;193.50.16.172.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
50.16.172.in-addr.arpa. 10800 IN SOA controller.wsvirt.home. root.wsvirt.home. 154 3600 1800 604800 86400
;; Query time: 5 msec
;; SERVER: 172.16.50.193#53(172.16.50.193)
;; WHEN: Wed Apr 01 17:20:44 IDT 2020
;; MSG SIZE rcvd: 118
$ dig -x 172.16.50.193
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> -x 172.16.50.193
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 62725
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;193.50.16.172.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
50.16.172.in-addr.arpa. 86400 IN SOA controller.wsvirt.home. root.wsvirt.home. 154 3600 1800 604800 86400
;; Query time: 0 msec
;; SERVER: 172.16.50.2#53(172.16.50.2)
;; WHEN: Wed Apr 01 17:20:56 IDT 2020
;; MSG SIZE rcvd: 118
答案4
最后,我发现了问题的根源。关键在于,Bind 9 在作为转发器工作时会剥离 DNSSEC 签名。我知道这一点,因此在named.conf
服务器上addc1.ad.wsvirt.home
我设置了以下选项作为解决方法:
dnssec-enable no;
dnssec-validation no;
但我忘了在 上做同样的事情controller.wsvirt.home
,现在我已经修复了我的疏忽,一切正常。显然, 的区域部分必须50.16.172.ddns
位于服务器上的 Bind 配置文件中addc1.ad.wsvirt.home
:
zone "50.16.172.ddns." {
type forward;
forwarders { 172.16.50.193; };
};