Docker 破坏主机的 DNS

Docker 破坏主机的 DNS

我按照此处的说明安装了 docker:

https://docs.docker.com/install/linux/docker-ce/debian/

我在使用 armbian buster (10)。问题是 docker0 破坏了主机的 dns,我不知道为什么。dns 也不适用于容器。

nmcli dev show | grep 'IP4.DNS'
IP4.DNS[1]:                             192.168.1.1

sudo route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1000   0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0

sudo ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:7b:98:37:66  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.160  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::2974:98e8:289b:f3fb  prefixlen 64  scopeid 0x20<link>
        ether 82:38:2f:c9:e0:80  txqueuelen 1000  (Ethernet)
        RX packets 1599  bytes 254405 (248.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1289  bytes 489915 (478.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 24  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 3150  bytes 1106993 (1.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3150  bytes 1106993 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

删除 docker0 后一切正常。如果有人能解释一下问题所在,我将不胜感激。

/etc/resolv.conf 的内容:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

# No DNS servers known.
sudo systemd-resolve status
status: resolve call failed: All attempts to contact name servers or networks failed

不使用docker时/etc/resolv.conf的内容:

# Generated by NetworkManager
search lan
nameserver 192.168.1.1

发行版是 debian 10 (armbian)

通过增加:

搜索局域网名称服务器 192.168.1.1

到 /etc/resolv.conf 它可以工作但重启后无法继续。

相关内容