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

有人可以告诉我使用带有2个桥接接口的KVM创建VM。 我有一台配置了Eth0和Eth1并连接到2个独立网络的服务器,我想在这个物理刀片中创建一个VM,以便VM连接到两个网络,这样我们就可以控制网络流量,即使在VM级别也是如此。 现在,我们只能让VM连接到br0,但是如何配置br1? 感谢帮助!

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

以下对我有用:

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 

现在,安装完成后,我手动将guest eth1添加到guest / 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编辑,这样您就不必重新安装VM):

     

编辑:

静态br0情况的主机和guest / 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