#事故现场

在Ubuntu系统中,安装docker,并以bridge网络模式启动容器,网络不通(无法访问外网),但使用host网络模式没有问题。

#解决方法

刚开始怀疑是DNS问题,后来发现是route问题。

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.154   0.0.0.0         UG    0      0        0 ens160
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 ens160
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     0.0.0.0         255.255.248.0   U     0      0        0 ens160

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    0      0        0 ens160
default         _gateway        0.0.0.0         UG    0      0        0 ens160
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     0.0.0.0         255.255.248.0   U     0      0        0 ens160

其中的一条route是错误的,需要删除:

route del default gw 192.168.1.154
netplan apply

问题解决!

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐