Sha*_*lan 5 networking kvm virtualization interface network-bridge
有人可以让我知道使用带有 2 个桥接接口的 KVM 创建一个 VM。我有一台配置了 Eth0 和 Eth1 并连接到 2 个独立网络的服务器,我想在这个物理刀片中创建一个虚拟机,以便虚拟机桥接到两个网络,这样我们甚至可以在虚拟机级别控制网络流量. 现在,我们只能让虚拟机连接到 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
Run Code Online (Sandbox Code Playgroud)
注意:我为 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
Run Code Online (Sandbox Code Playgroud)
现在,安装完成后,我手动将来宾 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
Run Code Online (Sandbox Code Playgroud)
请注意,有不为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>
Run Code Online (Sandbox Code Playgroud)
编辑:
静态 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
Run Code Online (Sandbox Code Playgroud)
寻求:
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
Run Code Online (Sandbox Code Playgroud)
以及主机上的路由表(作为检查):
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
Run Code Online (Sandbox Code Playgroud)