KVM,设置桥接网络

KVM,设置桥接网络

我在为 KVM 创建网桥时遇到了未知问题。我做了什么:我的操作系统:Ubuntu 18.04

  1. 我安装了 bridge-utils
sudo apt-get install bridge-utils
  1. 我修改了文件 /etc/netplan/50-cloud-init.yaml。内容如下:
network:
    version: 2
    ethernets:
        eno1:
            addresses: []
            dhcp4: true
        eno2:
            addresses: [192.168.0.101/24]
            gateway4: 192.168.0.1
            dhcp4: false
        enp4s0f0:
            addresses: []
            dhcp4: true
            optional: true
        enp4s0f1:
            addresses: []
            dhcp4: true
            optional: true
        enp5s0f0:
            addresses: []
            dhcp4: true
            optional: true
        enp5s0f1:
            addresses: []
            dhcp4: true
            optional: true

    bridges:
        br0:
            interfaces: [eno2]
            dhcp4: false
            addresses: [192.168.0.100/24]
            gateway4: 192.168.0.1
            nameservers:
                addresses: [192.168.0.1]
            parameters:
                stp: true
                forward-delay: 4
  1. 我运行了 netplan apply。一切顺利。现在我可以看到:
3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
    link/ether 78:2b:cb:33:29:3d brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.101/24 brd 192.168.0.255 scope global eno2
       valid_lft forever preferred_lft forever

8: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 52:54:00:43:8d:69 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever

  1. 我添加了网络的定义:host-bridge
virsh # net-dumpxml host-bridge
<network connections='1'>
  <name>host-bridge</name>
  <uuid>1823e6a7-3a86-4d7f-b612-27c003066faa</uuid>
  <forward mode='bridge'/>
  <bridge name='br0'/>
</network>
  1. 然后我使用以下命令安装新的虚拟机:
virt-install --name=debian-tutorial4 \
    --vcpus=4 \
    --memory=8192 \
    --cdrom=/vm-images/debian-10.0.0-amd64-netinst.iso \
    --disk size=10,format=raw \
    --os-variant=debian9 \
    --network network=default \
    --network network=host-bridge
  1. 当我运行时virsh dumpxml debian-tutorial4,我可以看到:
<interface type='network'>
    <mac address='52:54:00:48:0d:a2'/>
    <source network='default' bridge='virbr0'/>
    <target dev='vnet3'/>
    <model type='virtio'/>
    <alias name='net0'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<interface type='bridge'>
    <mac address='52:54:00:ca:51:97'/>
    <source network='host-bridge' bridge='br0'/>
    <target dev='vnet4'/>
    <model type='virtio'/>
    <alias name='net1'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>

当我登录到虚拟机并运行时ip a,我可以看到:

daniel@debian4:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:48:0d:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.173/24 brd 192.168.122.255 scope global dynamic ens3
       valid_lft 3534sec preferred_lft 3534sec
    inet6 fe80::5054:ff:fe48:da2/64 scope link 
       valid_lft forever preferred_lft forever
3: ens4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 52:54:00:ca:51:97 brd ff:ff:ff:ff:ff:ff

我需要做什么才能将我的虚拟机连接到桥接网络?


感谢您的答复。

主机上的接口已启动。

root@smaug:/home/daniel# ip a show br0 up
94: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 82:43:74:4e:8d:c4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::8043:74ff:fe4e:8dc4/64 scope link 
       valid_lft forever preferred_lft forever

从 eno2 中删除 IP

        eno2:
            addresses: []
            dhcp4: false

但我仍然无法在虚拟机上的接口上看到 IP。

答案1

在主机系统上检查br0接口的状态。它应该是启动的。

ens4在您的案例中,您应该在客户系统中配置接口。此接口对应于您的桥接网络。

此外,您不应该在eno2接口上分配任何 IP 地址,因为它是一个桥接端口接口(br0接口的从属接口)。

其他一切看上去都配置正确。

答案2

您将defaulthost-bridge网络都连接到域。不要这样做。使用 netplan 定义的桥接器,您将替换

--network network=default \
--network network=host-bridge

--network=host-bridge

这应该可以解决您的问题,因为访客将尝试使用 DHCP 配置第一个接口。

我还会禁用桥上的 STP。

启动后你的虚拟机brctl show br0应该如下所示:

bridge name     bridge id               STP enabled     interfaces
br0             8000.4ccc6a27d838       no              eth0
                                                        vnet0

答案3

最后我解决了我的问题:

解决方案:

在主机站点上一切正常。这是我安装的 Debian 的一些问题。

我通过 virt-viewer 登录,然后修改了/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
allow-hotplug ens3
iface ens3 inet dhcp

iface ens4 inet static
    address 192.168.0.110/24
    gateway 192.168.0.1

然后关闭和启动接口并重新启动网络

ip link set dev ens3 down
ip link set dev ens4 down
ip link set dev ens3 up
ip link set dev ens4 up

systemctl restart networking

然后重新加载dhcp:

/sbin/dhclient

最后我的虚拟机获得了 IP

root@debian4:/home/daniel# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:fa:76:1b brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.71/24 brd 192.168.122.255 scope global dynamic ens3
       valid_lft 3277sec preferred_lft 3277sec
    inet6 fe80::5054:ff:fefa:761b/64 scope link
       valid_lft forever preferred_lft forever
3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:71:c1:ed brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.110/24 brd 192.168.0.255 scope global ens4
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe71:c1ed/64 scope link
       valid_lft forever preferred_lft forever

相关内容