将单个NIC分配给KVM来宾

我有一个服务器,安装了6个网卡,并运行Ubuntu 12.04LTS。 我想用kvm设置4个访客虚拟机。 现在我想为主机分配2个网卡(1个公网IP和1个私有IP),并且每个网卡分配4个访客虚拟机(全部私有IP)。 我该怎么做呢?

/etc/network/interfaces 

我遇到了下面显示的configuration文件的问题:

 # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.109 netmask 255.255.255.0 gateway 192.168.1.5 auto eth1 iface eth1 inet static address 192.168.1.117 netmask 255.255.255.0 auto eth2 iface eth2 inet manual auto br0 iface br0 inet static address 192.168.1.118 netmask 255.255.255.0 bridge_ports eth2 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off auto eth3 iface eth3 inet manual auto br1 iface br1 inet static address 192.168.1.119 netmask 255.255.255.0 bridge_ports eth3 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off auto eth4 iface eth4 inet manual auto br2 iface br2 inet static address 192.168.1.123 netmask 255.255.255.0 bridge_ports eth4 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off auto eth5 iface eth5 inet manual auto br3 iface br3 inet static address 192.168.1.124 netmask 255.255.255.0 bridge_ports eth5 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off 

感谢解决scheme,我现在有它的工作。 唯一的问题是分配给guest虚拟机的NIC仍然在主机上获得一个IP,输出如下:

eth0 Link encap:Ethernet HWaddr 78:2b:cb:2b:61:ed
inet addr:192.168.1.109 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr:fe80 :: 7a2b:cbff:fe2b:61ed / 64作用域:链路UP BROADCAST运行多播MTU:1500度量:1 RX数据包:117错误: 0丢弃:0超限:0帧:0 TX数据包:108错误:0丢弃:0超载:0载波:0冲突:0 txqueuelen:1000 RX字节:26221(26.2 KB)TX字节:17217(17.2 KB)中断: 36内存:d2000000-d2012800

eth1 Link encap:Ethernet HWaddr 78:2b:cb:2b:61:ee
inet addr:192.168.1.10 Bcast:192.168.1.255掩码:255.255.255.0 inet6 addr:fe80 :: 7a2b:cbff:fe2b:61ee / 64作用域:链路UP BROADCAST运行多播MTU:1500度量:1 RX数据包:40错误: 0丢弃:0超限:0帧:0 TX包:14个错误:0丢弃:0超限:0载波:0冲突:0 txqueuelen:1000 RX字节:9898(9.8 KB)TX字节:3409(3.4 KB)中断: 48内存:d4000000-d4012800

eth2 Link encap:Ethernet HWaddr 00:10:18:a8:84:80
inet6 addr:fe80 :: 210:18ff:fea8:8480/64适用范围:链路UP BROADCAST运行多播MTU:1500度量标准:1个RX包:46个错误:0个丢弃:0个超限:0个帧:0个TX包:10个错误: 0丢包:0超限:0载波:0冲突:0 txqueuelen:1000 RX字节:11309(11.3 KB)TX字节:2523(2.5 KB)中断:47内存:da000000-da012800

eth3 Link encap:以太网HWaddr 00:10:18:a8:84:82
inet6 addr:fe80 :: 210:18ff:fea8:8482/64适用范围:链路UP BROADCAST运行多播MTU:1500度量标准:1个RX包:51个错误:0个丢弃:0个超限:0个帧:0个TX包:17个错误: 0丢弃:0超限:0载波:0冲突:0 txqueuelen:1000 RX字节:12541(12.5 KB)TX字节:4154(4.1 KB)中断:46内存:dc000000-dc012800

eth4 Link encap:Ethernet HWaddr 00:10:18:a8:84:84
inet6 addr:fe80 :: 210:18ff:fea8:8484/64适用范围:链路UP BROADCAST运行多播MTU:1500度量标准:1个RX包:55个错误:0个丢弃:0个超限:0个帧:0个TX包:13个错误: 0丢弃:0超限:0载波:0冲突:0 txqueuelen:1000 RX字节:15136(15.1 KB)TX字节:3053(3.0 KB)中断:38内存:d6000000-d6012800

eth5 Link encap:Ethernet HWaddr 00:10:18:a8:84:86
inet6 addr:fe80 :: 210:18ff:fea8:8486/64适用范围:链路UP BROADCAST运行多播MTU:1500度量标准:1个RX包:58个错误:0个丢弃:0个超限:0个帧:0个TX包:10个错误: 0丢弃:0超限:0载波:0冲突:0 txqueuelen:1000 RX字节:14742(14.7 KB)TX字节:2523(2.5 KB)中断:45内存:d8000000-d8012800

链路封装:本地环回
inet addr:127.0.0.1掩码:255.0.0.0 inet6 addr:1/128范围:主机UP LOOPBACK RUNNING MTU:16436度量标准:1 RX包:639错误:0丢弃:0超限:0帧:0 TX包: 639错误:0丢弃:0超限:0载波:0冲突:0 txqueuelen:0 RX字节:46422(46.4 KB)TX字节:46422(46.4 KB)

macvtap0链接封装:以太网HWaddr 52:54:00:8d:e7:e6
inet6 addr:fe80 :: 5054:ff:fe8d:e7e6 / 64适用范围:链路UP BROADCAST运行多播MTU:1500度量标准:1个RX包:57个错误:0个丢弃:0个超限:0个帧:0个TX包:7个错误: 0丢弃:0超限:0载波:0冲突:0 txqueuelen:500 RX字节:14074(14.0 KB)TX字节:1553(1.5 KB)

将NIC分配给guest虚拟机最简单的方法是将其保留在主机中,并对guest虚拟机NIC使用macvtap passthrough模式。 请注意,没有额外的更复杂的设置,这将阻止虚拟机实时迁移。

设置:

  <devices> ... <interface type='direct'> <source dev='eth0' mode='private'/> </interface> </devices> 

或者你可以去完整的PCI直通模式(假设你有IOMMU / VT-d):

  <devices> <interface type='hostdev'> <source> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </source> <mac address='52:54:00:6d:90:02'> </interface> </devices>