ubuntu server 18.04 启动时出现桥接问题

ubuntu server 18.04 启动时出现桥接问题

我在 ubuntu server 18.04 中遇到了网桥问题。这台机器有两个网卡,我将网桥绑定到其中一个,并将容器连接到网桥。我正在为容器上的局域网设置服务,并通过网桥使用静态 IP 使它们可用于子网。但是,当我启动系统时,我最终没有在网桥上获得 IP 地址:

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::7e8b:caff:fe03:57b0  prefixlen 64  scopeid 0x20<link>
        ether 7c:8b:ca:03:57:b0  txqueuelen 1000  (Ethernet)
        RX packets 167  bytes 19385 (19.3 KB)
        RX errors 0  dropped 50  overruns 0  frame 0
        TX packets 36  bytes 2946 (2.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::7e8b:caff:fe03:57b0  prefixlen 64  scopeid 0x20<link>
        ether 7c:8b:ca:03:57:b0  txqueuelen 1000  (Ethernet)
        RX packets 758  bytes 637232 (637.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 433  bytes 33998 (33.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 30:9c:23:41:a4:1b  txqueuelen 1000  (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

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 1000  (Local Loopback)
        RX packets 64  bytes 5104 (5.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 64  bytes 5104 (5.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethCHVFR2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fcf7:29ff:fe05:734b  prefixlen 64  scopeid 0x20<link>
        ether fe:f7:29:05:73:4b  txqueuelen 1000  (Ethernet)
        RX packets 348  bytes 26797 (26.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 422  bytes 350547 (350.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethLPOSTU: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fcb3:33ff:fe5b:4bbb  prefixlen 64  scopeid 0x20<link>
        ether fe:b3:33:5b:4b:bb  txqueuelen 1000  (Ethernet)
        RX packets 49  bytes 4363 (4.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 172  bytes 279551 (279.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

这是全局主机上的 /etc/network/interfaces 文件:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto enp2s0
iface enp2s0 inet manual

auto enp3s0
iface enp3s0 inet manual
#  address 192.168.5.19
#  netmask 255.255.255.0
#  gateway 192.168.5.1
#  dns-nameserver 8.8.8.8
#


auto br0
iface br0 inet static
        bridge_ports enp2s0
        address 192.168.5.20
#        network 192.168.5.0
        netmask 255.255.255.0
        broadcast 192.168.5.255
        gateway 192.168.5.1
#        bridge_fd 9
#        bridge_hello 2
#        bridge_maxage 12
        bridge_stp off
        dns-nameserver 8.8.8.8
        dns-search XXX.network

问题是,当我发出“服务网络重启”时,所有内容都按照预期的方式组合在一起:

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.5.20  netmask 255.255.255.0  broadcast 192.168.5.255
        inet6 fe80::7e8b:caff:fe03:57b0  prefixlen 64  scopeid 0x20<link>
        ether 7c:8b:ca:03:57:b0  txqueuelen 1000  (Ethernet)
        RX packets 122  bytes 12409 (12.4 KB)
        RX errors 0  dropped 21  overruns 0  frame 0
        TX packets 91  bytes 8072 (8.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 7c:8b:ca:03:57:b0  txqueuelen 1000  (Ethernet)
        RX packets 914  bytes 654161 (654.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 522  bytes 41870 (41.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 30:9c:23:41:a4:1b  txqueuelen 1000  (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

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 1000  (Local Loopback)
        RX packets 64  bytes 5104 (5.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 64  bytes 5104 (5.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethCHVFR2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fcf7:29ff:fe05:734b  prefixlen 64  scopeid 0x20<link>
        ether fe:f7:29:05:73:4b  txqueuelen 1000  (Ethernet)
        RX packets 350  bytes 26933 (26.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 430  bytes 351218 (351.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethLPOSTU: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fcb3:33ff:fe5b:4bbb  prefixlen 64  scopeid 0x20<link>
        ether fe:b3:33:5b:4b:bb  txqueuelen 1000  (Ethernet)
        RX packets 54  bytes 4625 (4.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 180  bytes 280218 (280.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

一切都开始正常工作。有什么想法我应该查看哪里才能让网络正常启动,而不是需要重新配置才能进行配置?

谢谢!

答案1

原来是 ifupdown 和 netplan 之间的交互。配置 netplan 后,系统正常运行。我怀疑问题是启动过程中的定时问题,由于网络子系统的关键部分尚未启动,因此无法为网桥分配地址。我清除了 ifupdown 并配置了 netplan,一切开始正常工作。

感谢@chili555 为我指明正确的方向。

相关内容