我正在尝试关注教程关于如何设置作为 docker 镜像托管的 DNS 服务器。
但我当然也面临问题。
我有如下设置named.conf
文件。但我完全不确定应该输入什么 IP 地址,我输入了本地机器(我用来运行 docker)的默认网关 ip:
acl internal {
192.168.1.0/24;
192.168.0.0/24;
127.0.0.1;
localhost;
192.168.0.144;
};
options {
forwarders {
8.8.8.8;
8.8.4.4;
};
allow-query { internal; };
};
zone "test.home." IN {
type master;
file "/etc/bind/test-home.zone";
};
下面我附加test-home.zone
文件
$TTL 2d
$ORIGIN test.home.
@ IN SOA test.home. root.test.home. (
202306151534 ; serial
12h
15m
3w
2h
)
IN NS ns.test.home.
@ IN NS ns.test.home.
ns IN A 172.19.0.1
test-name IN A 192.168.0.144
经过这样的设置,我可以使用命令解析已知名称:
nslookup google.com 172.19.0.1
上述命令的输出:
Server: UnKnown
Address: 172.19.0.1
Non-authoritative answer:
Name: google.com
Addresses: 2a00:1450:401b:814::200e
142.250.203.142
但是当我尝试解析我的名字时,它找不到域名:
nslookup test-name.test.home 172.19.0.1
输出:
Server: UnKnown
Address: 172.19.0.1
*** UnKnown can't find test-name.test.home: Non-existent domain
其他详情:
我在 Ubuntu 上运行我的 docker 镜像
我使用 Bind9 作为 DNS 服务器。
以下是托管 DNS 服务器的容器的 docker inspect 命令的输出:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "4b80c61e0f521afd51926708b1bfcc0fdb71a755566114af9cbe93cd0a44a462",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"53/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "53"
}
],
"53/udp": [
{
"HostIp": "0.0.0.0",
"HostPort": "53"
}
],
"953/tcp": null
},
"SandboxKey": "/var/run/docker/netns/4b80c61e0f52",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"dns-experiments_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"bind9",
"ab0859f8c64b"
],
"NetworkID": "9d5d03264503be5fee52e99bc04407da0d41f87eff3b07393805bc7aa019c734",
"EndpointID": "e8612947adc69d959dbac41abf78f8f14b7394efb5bb11a4d453e8bea745c298",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:13:00:02",
"DriverOpts": null
}
}
}
所以问题是:它似乎无法test-name.test.home
正确解析我的名字。为什么?我该如何修复?
更新
根据评论的建议,我尝试使用 docker inspect 输出中的 IP 地址,但也没有用。执行时nslookup
我只得到:
DNS request timed out.
timeout was 2 seconds.
DNS request timed out.
timeout was 2 seconds.
DNS request timed out.
timeout was 2 seconds.
DNS request timed out.
timeout was 2 seconds.
*** Request to UnKnown timed-out
答案1
解决方案终究是显而易见的。
我刚刚跑了
named-checkzone test.home test-home.zone
命令,结果发现它有两个问题:
- 序列号超出范围(例如,仅指定 230616 有效)
- 文件没有以换行符结束
修复它之后,我named-checkzone
再次运行并且它返回 OK 并且我可以成功解析我的 DNS 条目。