KVM-创建具有 2 个桥接接口的虚拟机

KVM-创建具有 2 个桥接接口的虚拟机

有人可以告诉我如何使用带有 2 个桥接接口的 KVM 创建虚拟机吗?

我有一台配置了 Eth0 和 Eth1 并连接到 2 个独立网络的服务器。我想在这个物理刀片内创建一个虚拟机,以便虚拟机桥接至两个网络,这样我们甚至可以在虚拟机级别控制网络流量。

目前,我们只能让虚拟机连接到 br0,但我该如何配置 br1?非常感谢您的帮助!

在我的 qemu xml 文件中,我有以下内容:

<interface type='bridge'>
 <mac address='00:11:22:33:44:55'/>
 <source bridge='br0'/>
 <model type='virtio'/>
 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

答案1

以下对我有用:

sudo virt-install -n virt64_01 -r 8192 \
--disk path=/media/newhd/virt64_01.img,bus=virtio,size=50 \
-c ubuntu-14.04.1-server-amd64.iso \
--network bridge=br0,model=virtio,mac=52:54:00:b2:cb:b0 \
--network bridge=br1,model=virtio \
--video=vmvga --graphics vnc,listen=0.0.0.0 --noautoconsole -v --vcpus=4

注意:我指定 BR0 的 MAC 地址,因为我的主服务器 dhcp 服务器和 DNS 中已经有该 VM 名称,我想避免自己做更多工作。对于 BR1,我在安装过程中并不关心,它会在稍后进行设置。

作为参考,这是我的 Ubutuntu 14.04 服务器主机上的 /etc/network/interfaces 文件:

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

# The loopback network interface
auto lo
iface lo inet loopback

# Local network interface
auto br1
iface br1 inet static
 address 192.168.222.1
 network 192.168.222.0
 netmask 255.255.255.0
 broadcast 192.168.222.255
 bridge_ports eth1
 bridge_fd 9
 bridge_hello 2
 bridge_maxage 12
 bridge_stp off

# The primary network interface and bridge
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

现在,安装完成后,我手动将客户机 eth1 添加到客户机 /etc/network/interfaces 文件中:

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

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

# Local network interface
auto eth1
iface eth1 inet static
 address 192.168.222.5
 network 192.168.222.0
 netmask 255.255.255.0
 broadcast 192.168.222.255

请注意不是为 eth1 指定的网关。如果指定了网关,则它将使主接口和路由表相应地填充。(就我的情况以及此答案而言,网关是假的,指定网关后,一切就停止工作了。最初,在指定了假网关的主机服务器上一切正常,但最终它也更改为使用 br1 作为主接口,一切就停止工作了,因此我已将其完全编辑掉。如果需要,另一种方法是明确管理路由表。)

这是定义 xml 文件的相关部分(即您可能能够使用 virsh edit,这样您就不必重新安装 VM):

<interface type='bridge'>
  <mac address='52:54:00:b2:cb:b0'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<interface type='bridge'>
  <mac address='52:54:00:d7:31:77'/>
  <source bridge='br1'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>

编辑:

静态 br0 情况的主机和客户机 /etc/network/interfaces 文件是:

主持人:

doug@s15:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# Local network interface
auto br1
iface br1 inet static
  address 192.168.222.1
  network 192.168.222.0
  netmask 255.255.255.0
  broadcast 192.168.222.255
  bridge_ports eth1
  bridge_fd 9
  bridge_hello 2
  bridge_maxage 12
  bridge_stp off

# The primary network interface and bridge
auto br0
#iface br0 inet dhcp
iface br0 inet static
  address 192.168.111.112
  network 192.168.111.0
  netmask 255.255.255.0
  gateway 192.168.111.1
  broadcast 192.168.111.255
  dns-search smythies.com
  dns-nameservers 192.168.111.1
  bridge_ports eth0
  bridge_fd 9
  bridge_hello 2
  bridge_maxage 12
  bridge_stp off

寻求:

doug@virt64-01:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# Local network interface
auto eth1
iface eth1 inet static
  address 192.168.222.5
  network 192.168.222.0
  netmask 255.255.255.0
  broadcast 192.168.222.255

# The primary network interface
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
  address 192.168.111.213
  network 192.168.111.0
  netmask 255.255.255.0
  broadcast 192.168.111.255
  gateway 192.168.111.1
  dns-search smythies.com
  dns-nameservers 192.168.111.1

主机上的路由表(作为检查):

doug@s15:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.111.1   0.0.0.0         UG    0      0        0 br0
192.168.111.0   0.0.0.0         255.255.255.0   U     0      0        0 br0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.222.0   0.0.0.0         255.255.255.0   U     0      0        0 br1

相关内容