我使用以下文件在 Ubuntu 20.04 上安装并配置了 bind9:
root@server:/etc/bind# cat named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
listen-on { any; };
allow-transfer { none; };
allow-query { any; };
recursion yes;
allow-recursion { 127.0.0.1; };
forwarders { 8.8.8.8; };
querylog yes;
//========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation auto;
listen-on-v6 { any; };
};
root@server:/etc/bind# cat named.conf.default-zones
...
zone "site" {
type master;
file "/etc/bind/site";
};
root@server:/etc/bind# cat site
$TTL 86400
mydomain.com. IN SOA ns1.mydomain.com. my.email.gmail.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
86400 ); ; Negative Cache TTL
mydomain.com. IN NS ns1.mydomain.com.
mydomain.com. IN NS ns2.mydomain.com.
mydomain.com. IN A ipv4
www IN A ipv4
ns1 IN A ipv4
ns2 IN A ipv4
ufw status
:
53/tcp ALLOW Anywhere
53/udp ALLOW Anywhere
root@server:/etc/bind# netstat -tulpn | grep 53
tcp 0 0 server-ip:53 0.0.0.0:* LISTEN 2649/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2649/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 2649/named
udp 0 0 server-ip:53 0.0.0.0:* 2649/named
udp 0 0 127.0.0.1:53 0.0.0.0:* 2649/named
这是系统日志错误,当我dig
(无论我dig
来自像服务器dig @localhost
,还是来自我的笔记本电脑dig @serveripv4
):
root@server:/etc/bind# tailf /var/log/syslog | grep named
Jun 29 20:23:25 server named[2649]: client @0x7f1930005910 my-laptop-ip#40259 (ns1.mydomain.com): query: ns1.mydomain.com IN A +E(0)K (server-ip)
Jun 29 20:23:25 server named[2649]: client @0x7f1930005910 my-laptop-ip#40259 (ns1.mydomain.com): query (cache) 'ns1.mydomain.com/A/IN' denied
Jun 29 20:23:25 server named[2649]: client @0x7f1930005910 my-laptop-ip#40259 (ns1.mydomain.com): query failed (REFUSED) for ns1.mydomain.com/IN/A at query.c:5425
我无法使用 dns 和 dig 的配置有什么问题?
为每个
zone{}
块指定的名称必须与正在服务的实际 DNS 区域(域)匹配——它不仅仅是一个任意标签。现在,您的 DNS 服务器配置为为名为 的域提供服务
site
,但没有任何与您尝试查询的名称匹配的区域(它既没有mydomain.com
区域,也没有ns1.mydomain.com
区域,也没有com
区域)。