Linux 有没有办法配置Docker';s嵌入式DNS服务器';s上游名称服务器';s港? 一般情况
Docker守护程序附带一个嵌入式DNS服务器。它解析本地Docker swarm和网络记录,并将外部记录查询转发给配置了--dns的上游名称服务器 文档说,您可以使用Linux 有没有办法配置Docker';s嵌入式DNS服务器';s上游名称服务器';s港? 一般情况,linux,docker,dns,Linux,Docker,Dns,Docker守护程序附带一个嵌入式DNS服务器。它解析本地Docker swarm和网络记录,并将外部记录查询转发给配置了--dns的上游名称服务器 文档说,您可以使用--dns=[IP\u address…]设置此上游名称服务器的IP地址。使用的默认端口是53 我的问题 我可以配置使用的端口吗 我的主机的/etc/docker/daemon.json显示“dns”:[“10.99.0.1”],。我是否有办法指定类似于“dns”:[“10.99.0.1:53”],以便dockerd始终知道将dn
--dns=[IP\u address…]
设置此上游名称服务器的IP地址。使用的默认端口是53
我的问题
我可以配置使用的端口吗
我的主机的/etc/docker/daemon.json
显示“dns”:[“10.99.0.1”],
。我是否有办法指定类似于“dns”:[“10.99.0.1:53”]
,以便dockerd始终知道将dns查询转发到端口53
我的用例
在我的例子中,10.99.0.1是本地主机网桥接口的IP。我在此主机上运行本地DNS缓存服务器。因此,发送到10.99.0.1:53的DNS查询可以正常工作。但是dockerd将来自连接到用户定义网桥网络(使用docker network create
创建)的容器的查询转发到它选择的非标准端口。参见下面的终端输出
详细的终端输出和调试信息
“toogle”是一个Docker容器,连接到我用Docker network create
创建的Docker网络。127.0.0.11是另一个环回地址。来自连接到用户定义的Docker网络的Docker容器内的DNS查询将发送到此IP
Docker的嵌入式DNS服务器实际运行吗
DNS查询通过toogle的防火墙规则以这种方式路由
$ sudo nsenter -n -t $(docker inspect --format {{.State.Pid}} toogle) iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 1 packets, 60 bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 1 packets, 60 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DOCKER_OUTPUT all -- * * 0.0.0.0/0 127.0.0.11
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DOCKER_POSTROUTING all -- * * 0.0.0.0/0 127.0.0.11
Chain DOCKER_OUTPUT (1 references)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- * * 0.0.0.0/0 127.0.0.11 tcp dpt:53 to:127.0.0.11:37619 <-- look at this rule
0 0 DNAT udp -- * * 0.0.0.0/0 127.0.0.11 udp dpt:53 to:127.0.0.11:58552 <-- look at this rule
Chain DOCKER_POSTROUTING (1 references)
pkts bytes target prot opt in out source destination
0 0 SNAT tcp -- * * 127.0.0.11 0.0.0.0/0 tcp spt:37619 to::53
0 0 SNAT udp -- * * 127.0.0.11 0.0.0.0/0 udp spt:58552 to::53
但两人都没有DNS回复
$ sudo nsenter -n -t $(docker inspect --format {{.State.Pid}} toogle) dig @127.0.0.11 -p 58552 accounts.google.com
; <<>> DiG 9.11.3-1ubuntu1.14-Ubuntu <<>> @127.0.0.11 -p 58552 accounts.google.com
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached
$ sudo nsenter -n -t $(docker inspect --format {{.State.Pid}} toogle) dig @127.0.0.11 -p 37619 accounts.google.com +tcp
; <<>> DiG 9.11.3-1ubuntu1.14-Ubuntu <<>> @127.0.0.11 -p 37619 accounts.google.com +tcp
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached
但是dockerd正在尝试将DNS查询转发到10.99.0.1,这是我的docker0网桥网络接口
$ sudo journalctl --follow -u docker
-- Logs begin at Tue 2019-11-05 18:17:27 UTC. --
Apr 22 15:43:12 my-host dockerd[10984]: time="2021-04-22T15:43:12.496979903Z" level=debug msg="[resolver] read from DNS server failed, read udp 172.20.0.127:37928->10.99.0.1:53: i/o timeout"
Apr 22 15:43:13 my-host dockerd[10984]: time="2021-04-22T15:43:13.496539033Z" level=debug msg="Name To resolve: accounts.google.com."
Apr 22 15:43:13 my-host dockerd[10984]: time="2021-04-22T15:43:13.496958664Z" level=debug msg="[resolver] query accounts.google.com. (A) from 172.20.0.127:51642, forwarding to udp:10.99.0.1"
dockerd将请求名称服务器127.0.0.11:58552的DNS查询转发到10.99.0.1,但只更改IP而不更改端口。因此,DNS查询被转发到10.99.0.1:58552,并且该端口上没有任何内容正在侦听
$ dig @10.99.0.1 -p 58552 accounts.google.com
[NO RESPONSE]
$ nc 10.99.0.1 58552 -vz
10.99.0.1: inverse host lookup failed: Unknown host
(UNKNOWN) [10.99.0.1] 58552 (?) : Connection refused
对10.99.0.1:53的DNS查询按预期工作
dig @10.99.0.1 -p 53 accounts.google.com
; <<>> DiG 9.11.3-1ubuntu1.14-Ubuntu <<>> @10.99.0.1 -p 53 accounts.google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53674
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;accounts.google.com. IN A
;; ANSWER SECTION:
accounts.google.com. 235 IN A 142.250.1.84
;; Query time: 0 msec
;; SERVER: 10.99.0.1#53(10.99.0.1)
;; WHEN: Thu Apr 22 17:20:09 UTC 2021
;; MSG SIZE rcvd: 64
dig@10.99.0.1-p53 accounts.google.com
; 挖掘9.11.3-1ubuntu1.14-Ubuntu@10.99.0.1-p53 accounts.google.com
; (找到1台服务器)
;; 全局选项:+cmd
;; 得到答案:
;; ->>HEADER我认为没有办法做到这一点。我还误读了输出。Docker守护进程正在转发到端口53
读取udp 172.20.0.127:37928->10.99.0.1:53:i/o超时
$ dig @10.99.0.1 -p 58552 accounts.google.com
[NO RESPONSE]
$ nc 10.99.0.1 58552 -vz
10.99.0.1: inverse host lookup failed: Unknown host
(UNKNOWN) [10.99.0.1] 58552 (?) : Connection refused
dig @10.99.0.1 -p 53 accounts.google.com
; <<>> DiG 9.11.3-1ubuntu1.14-Ubuntu <<>> @10.99.0.1 -p 53 accounts.google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53674
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;accounts.google.com. IN A
;; ANSWER SECTION:
accounts.google.com. 235 IN A 142.250.1.84
;; Query time: 0 msec
;; SERVER: 10.99.0.1#53(10.99.0.1)
;; WHEN: Thu Apr 22 17:20:09 UTC 2021
;; MSG SIZE rcvd: 64