无法成功设置与 Netplan 的桥接接口,以支持带有 KVM 的来宾操作系统

无法成功设置与 Netplan 的桥接接口,以支持带有 KVM 的来宾操作系统

首先,我想为我糟糕的英语道歉。

我通常会在几个小时、几天甚至几周的研究后找到答案,但今天,我感到很失落,希望得到一些帮助。

目标:

我的目标是与 Netplan 设置桥接接口。该桥接口将通过 DHCP 向我的来宾操作系统 (KVM) 提供 IP 地址。

问题:

我的来宾操作系统无法通过桥接口建立连接。问题可能来自 Netplan 的配置或用于安装来宾操作系统的参数。

语境:

我的服务器运行 Ubuntu Bionic 18.04 LTS,它是由外部提供商托管的云服务器。我想要安装的客户操作系统也是 Ubuntu Bionic 18.04 LTS 发行版。我的服务器支持硬件虚拟化,能够运行硬件加速的KVM虚拟机。

主机操作系统的初始网络状态:

的输出ifconfig -a是:

ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 10.52.16.185  netmask 255.255.255.0  broadcast 10.52.16.255
    inet6 fe80::f816:3eff:fe82:c5fe  prefixlen 64  scopeid 0x20<link>
    inet6 2001:1600:4:8:f816:3eff:fe82:c5fe  prefixlen 64  scopeid 0x0<global>
    ether fa:16:3e:82:c5:fe  txqueuelen 1000  (Ethernet)
    RX packets 255880  bytes 22882442 (22.8 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 582  bytes 49337 (49.3 KB)
    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 138  bytes 10546 (10.5 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 138  bytes 10546 (10.5 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

的输出ip route是:

default via 10.52.16.1 dev ens3 proto dhcp metric 100 
10.52.11.0/24 dev ens3 proto dhcp scope link metric 100 
10.52.16.0/24 dev ens3 proto kernel scope link src 10.52.16.185 
10.52.20.0/24 dev ens3 proto dhcp scope link metric 100 
10.52.24.0/24 dev ens3 proto dhcp scope link metric 100 
169.254.169.254 via 10.52.16.1 dev ens3 proto dhcp metric 100

的输出lspci是:

00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:05.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:06.0 Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon

$ networkctl -a 状态

● 1: lo
   Link File: /lib/systemd/network/99-default.link
Network File: n/a
        Type: loopback
       State: carrier (unmanaged)
     Address: 127.0.0.1
              ::1

● 2: ens3
   Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-ens3.network
        Type: ether
       State: routable (configured)
        Path: pci-0000:00:03.0
      Driver: virtio_net
      Vendor: Red Hat, Inc.
       Model: Virtio network device
  HW Address: fa:16:3e:82:c5:fe
     Address: 10.52.16.185
              2001:1600:4:8:f816:3eff:fe82:c5fe
              fe80::f816:3eff:fe82:c5fe
     Gateway: 10.52.16.1
              fe80::f816:3eff:fee7:1ea5
         DNS: XX.XX.XX.XX
              YY.YY.YY.YY
Search Domains: myprovider.ext

到目前为止我所做的:

第一步是创建一个桥接口br0。自从我运行 Ubuntu 18 以来,我应该为此使用 Netplan。

Netplan中的初始配置/etc/netplan/50-cloud-init.yaml是:

network:
version: 2
ethernets:
    ens3:
        dhcp4: true
        match:
            macaddress: fa:16:3e:82:c5:fe
        mtu: 8950
        set-name: ens3

我用这个配置做了很多测试,但我的桥接接口 (br0) 无法获得 IP。我最终使用 NetworkManager 作为渲染器,并且以下/etc/netplan/50-cloud-init.yaml配置有效:

network:
version: 2
renderer: NetworkManager
ethernets:
    ens3:
        dhcp4: false
        dhcp6: false
        match:
            macaddress: fa:16:3e:82:c5:fe
        set-name: ens3
        mtu: 8950
bridges:
    br0:
        interfaces: [ens3]
        dhcp4: true
        dhcp6: false
        mtu: 8950
        parameters:
            stp: true
            forward-delay: 4

使用 Netplan 的输出ifconfig -a是:

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 8950
    inet 10.52.16.185  netmask 255.255.255.0  broadcast 10.52.16.255
    inet6 fe80::f816:3eff:fe82:c5fe  prefixlen 64  scopeid 0x20<link>
    inet6 2001:1600:4:8:f816:3eff:fe82:c5fe  prefixlen 64  scopeid 0x0<global>
    ether fa:16:3e:82:c5:fe  txqueuelen 1000  (Ethernet)
    RX packets 6364  bytes 468754 (468.7 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 75  bytes 11528 (11.5 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 8950
    ether fa:16:3e:82:c5:fe  txqueuelen 1000  (Ethernet)
    RX packets 8132  bytes 713045 (713.0 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 114  bytes 13490 (13.4 KB)
    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 176  bytes 11840 (11.8 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 176  bytes 11840 (11.8 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

使用 Netplan的输出ip route是:

10.52.11.0/24 dev br0 proto dhcp scope link metric 425 
10.52.16.0/24 dev br0 proto kernel scope link src 10.52.16.185 metric 425 
10.52.20.0/24 dev br0 proto dhcp scope link metric 425 
10.52.24.0/24 dev br0 proto dhcp scope link metric 425 
169.254.169.254 via 10.52.16.1 dev br0 proto dhcp metric 425

使用 Netplan的输出lspci是:

00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
00:04.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:05.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:06.0 Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon

使用 Netplan的输出networkctl -a status是:

● 1: lo
   Link File: /lib/systemd/network/99-default.link
Network File: n/a
        Type: loopback
       State: carrier (unmanaged)
     Address: 127.0.0.1
              ::1

● 2: ens3
   Link File: /run/systemd/network/10-netplan-ens3.link
Network File: n/a
        Type: ether
       State: carrier (unmanaged)
        Path: pci-0000:00:03.0
      Driver: virtio_net
      Vendor: Red Hat, Inc.
       Model: Virtio network device
  HW Address: fa:16:3e:82:c5:fe

● 3: br0
   Link File: /lib/systemd/network/99-default.link
Network File: n/a
        Type: ether
       State: routable (unmanaged)
      Driver: bridge
  HW Address: fa:16:3e:82:c5:fe
     Address: 10.52.16.185
              2001:1600:4:8:f816:3eff:fe82:c5fe
              fe80::f816:3eff:fe82:c5fe
     Gateway: 10.52.16.1
              fe80::f816:3eff:fee7:1ea5

来宾操作系统安装:

现在我的桥接界面看起来不错,我安装了虚拟化所需的软件包 ( qemu qemu-kvm libvirt-bin bridge-utils virt-manager) 并启动了libvirtd服务。

然后,我尝试使用virt-install以下命令安装我的第一个来宾操作系统:

$ sudo virt-install \
--name projectname \
--ram 1024 \
--vcpus 1 \
--network bridge:br0 \
--disk path=/srv/data/projectname,size=2 \
--os-type Linux \
--os-variant=ubuntu18.04 \
--location 'http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/' \
--graphics none \
--extra-args 'console=ttyS0' \
--console pty,target_type=serial

不幸的是,安装程序无法使用 DHCP 配置网络,如下所示:

网络自动配置失败

尝试安装来宾操作系统失败后的网络状态:

的输出ifconfig -a是:

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 8950
    inet 10.52.16.185  netmask 255.255.255.0  broadcast 10.52.16.255
    inet6 fe80::f816:3eff:fe82:c5fe  prefixlen 64  scopeid 0x20<link>
    inet6 2001:1600:4:8:f816:3eff:fe82:c5fe  prefixlen 64  scopeid 0x0<global>
    ether fa:16:3e:82:c5:fe  txqueuelen 1000  (Ethernet)
    RX packets 289453  bytes 301978563 (301.9 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 70249  bytes 7101505 (7.1 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 8950
    ether fa:16:3e:82:c5:fe  txqueuelen 1000  (Ethernet)
    RX packets 294080  bytes 306373898 (306.3 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 71779  bytes 7183441 (7.1 MB)
    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 332  bytes 27936 (27.9 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 332  bytes 27936 (27.9 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
    ether 52:54:00:06:10:e5  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

virbr0-nic: flags=4098<BROADCAST,MULTICAST>  mtu 1500
    ether 52:54:00:06:10:e5  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

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 8950
    inet6 fe80::fc54:ff:fe8e:6a11  prefixlen 64  scopeid 0x20<link>
    ether fe:54:00:8e:6a:11  txqueuelen 1000  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 1  bytes 90 (90.0 B)
    TX errors 0  dropped 108892 overruns 0  carrier 0  collisions 0

的输出ip route是:

default via 10.52.16.1 dev br0 proto dhcp metric 425 
10.52.11.0/24 dev br0 proto dhcp scope link metric 425 
10.52.16.0/24 dev br0 proto kernel scope link src 10.52.16.185 metric 425 
10.52.20.0/24 dev br0 proto dhcp scope link metric 425 
10.52.24.0/24 dev br0 proto dhcp scope link metric 425 
169.254.169.254 via 10.52.16.1 dev br0 proto dhcp metric 425 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown

的输出lspci是:

00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:04.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:05.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon

的输出networkctl -a status是:

● 1: lo
   Link File: n/a
Network File: n/a
        Type: loopback
       State: carrier (unmanaged)
     Address: 127.0.0.1
              ::1

● 2: ens3
   Link File: n/a
Network File: n/a
        Type: ether
       State: carrier (unmanaged)
        Path: pci-0000:00:03.0
      Vendor: Red Hat, Inc.
       Model: Virtio network device
  HW Address: fa:16:3e:82:c5:fe

● 3: br0
   Link File: n/a
Network File: n/a
        Type: ether
       State: routable (unmanaged)
      Driver: bridge
  HW Address: fa:16:3e:82:c5:fe
     Address: 10.52.16.185
              2001:1600:4:8:f816:3eff:fe82:c5fe
              fe80::f816:3eff:fe82:c5fe
     Gateway: 10.52.16.1
              fe80::f816:3eff:fee7:1ea5

● 4: virbr0
   Link File: /lib/systemd/network/99-default.link
Network File: n/a
        Type: ether
       State: no-carrier (unmanaged)
      Driver: bridge
  HW Address: 52:54:00:06:10:e5
     Address: 192.168.122.1

● 5: virbr0-nic
   Link File: /lib/systemd/network/99-default.link
Network File: n/a
        Type: ether
       State: off (unmanaged)
      Driver: tun
  HW Address: 52:54:00:06:10:e5

● 7: vnet0
   Link File: /lib/systemd/network/99-default.link
Network File: n/a
        Type: ether
       State: degraded (unmanaged)
      Driver: tun
  HW Address: fe:54:00:8e:6a:11
     Address: fe80::fc54:ff:fe8e:6a11

我尝试了上面相同的命令,但将 br0 替换为 virbr0。安装成功,但这看起来是错误的(基于我迄今为止看到的所有教程......)。

问题

  • 我应该使用 Netplan 还是完全删除它?
  • 应该使用默认的网络渲染器还是使用 NetworkManager 好?
  • 我的 Netplan 配置正确吗?
  • virt-install 参数是否正确?
  • ...我究竟做错了什么 ?

相关内容