我有一台装有 Ubuntu 18.04(最近从 16.04 升级)的服务器,它运行两个 qemu-kvm VM。
服务器有两个网络接口,但只有第一个已连接。第二个目前未使用/有线。
对于网络,我设置了一个网桥,只要我手动执行,它就可以正常工作ip link set enp6s0f1 down
。在我手动关闭它之前,我遇到了大量的数据包丢失,因为来自主机的流量似乎使用了两个接口。
虚拟机上的网络连接正常(Windows 10 和 Ubuntu 18.04)。所有其他主机和互联网均可从虚拟机访问。虚拟机可从网络中的所有主机访问。
netplan 配置:
network:
version: 2
renderer: networkd
ethernets:
enp6s0f0:
optional: true
enp6s0f1:
optional: true
bridges:
br0:
interfaces:
- enp6s0f0
addresses: [10.0.0.11/24]
gateway4: 10.0.0.1
nameservers:
search:
- domain.example.com
addresses:
- "10.0.0.25"
- "10.0.0.26"
为了手册的完整性ip link set enp6s0f1 down
:
andi@node-002:~$ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.11 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::c804:4dff:febe:597e prefixlen 64 scopeid 0x20<link>
ether ca:04:4d:be:59:7e txqueuelen 1000 (Ethernet)
RX packets 1261 bytes 87931 (87.9 KB)
RX errors 0 dropped 126 overruns 0 frame 0
TX packets 537 bytes 191015 (191.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp6s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::230:48ff:febb:9124 prefixlen 64 scopeid 0x20<link>
ether 00:30:48:bb:91:24 txqueuelen 1000 (Ethernet)
RX packets 1036 bytes 118241 (118.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 425 bytes 204536 (204.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 18 memory 0xdc020000-dc040000
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 144 bytes 13404 (13.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 144 bytes 13404 (13.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fed5:32c0 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:d5:32:c0 txqueuelen 1000 (Ethernet)
RX packets 1199 bytes 205808 (205.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1839 bytes 278772 (278.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fe12:52c9 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:12:52:c9 txqueuelen 1000 (Ethernet)
RX packets 1030 bytes 230817 (230.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1567 bytes 214331 (214.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
到目前为止我已经尝试过:
- 在 netplan 中省略 enp6s0f1 接口
- 将两个接口添加到桥接中
- 在 BIOS 中关闭第二个接口,但这是不可能的
- 创建一个网络钩子脚本来关闭接口启动。但我想我在这里做错了什么
后续脚本/etc/networkd-dispatcher/routable.d:
#!/bin/bash
ip link set enp6s0f1 down
编辑:我找到了一个解决方法。但我不认为这是解决问题的办法。目前不需要并连接第二个网络接口,在未使用的子网中配置静态 IP 不会导致丢失数据包。它有效,但并不好。因此,我不会将此作为答案发布。
这是解决方法/etc/netplan/config.yaml
:
network:
version: 2
renderer: networkd
ethernets:
enp6s0f0:
optional: true
enp6s0f1:
addresses: [10.254.0.10/24] # <- static IP in different subnet.
optional: true
bridges:
br0:
interfaces:
- enp6s0f0
addresses: [10.0.0.11/24]
gateway4: 10.0.0.1
nameservers:
search:
- domain.example.com
addresses:
- "10.0.0.25"
- "10.0.0.26"
期待更好的解决方案。
答案1
有一个选项:ignore-carrier
需要设置为true
ignore-carrier (boolean) – since 0.104
(networkd back end only) Allow the specified interface to be configured even if it has no carrier.