在kvm上路由networking

有很多用于KVM连网的configuration。 但我无法从主持人或外部到达客人。 我正在使用Ubuntu 11.04。 在客人我有一个WindowsXP与DHCP。

我想要客人在主机的同一个networking。 我试图使用IP别名

我在/ etc / network / interfaces中build立了桥接networking

auto eth0 iface eth0 inet manual auto eth0:1 iface eth0:1 inet static address 192.168.0.11 netmask 255.255.255.0 auto br0 iface br0 inet static address 192.168.0.10 netmask 255.255.255.0 gateway 192.168.0.1 bridge_ports eth0 bridge_stp off bridge_fd 0 bridge_maxwait 0 

然后在/etc/libvirtd/qemu/network/default.xml中更改默认networking

 <network> <name>default</name> <uuid>831a93e1-0b84-0b0e-9ca2-23c407983968</uuid> <forward mode='route'/> <bridge name='virbr0' stp='on' delay='0' /> <ip address='192.168.122.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.122.100' end='192.168.122.254' /> <host mac='52:54:00:7c:df:88' name='vm' ip='192.168.122.99' /> </dhcp> </ip> </network> 

/etc/libvirt/qemu/vm.xml中的networking

 <interface type='network'> <mac address='52:54:00:7c:df:88'/> <source network='default'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> 

来自DHCP的客人得到正确的IP。 最后将外部接口的stream量引导到内部和后面

 sudo iptables -t nat -A PREROUTING -d 192.168.0.11 -j DNAT --to-destination 192.168.122.99 sudo iptables -t nat -A POSTROUTING -d 192.168.122.99 -j SNAT --to-source 192.168.0.11 

所以最后的configuration是这样的:

 $> brctl show bridge name bridge id STP enabled interfaces br0 8000.0026b902076d no eth0 virbr0 8000.fe54007cdf88 yes vnet0 $> route Tabella di routing IP del kernel Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 br0 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0 link-local * 255.255.0.0 U 1000 0 0 br0 default 192.168.0.1 0.0.0.0 UG 100 0 0 br0 $> ifconfig br0 Link encap:Ethernet HWaddr 00:26:b9:02:07:6d indirizzo inet:192.168.0.10 Bcast:192.168.0.255 Maschera:255.255.255.0 eth0 Link encap:Ethernet HWaddr 00:26:b9:02:07:6d indirizzo inet6: fe80::226:b9ff:fe02:76d/64 Scope:Link eth0:1 Link encap:Ethernet HWaddr 00:26:b9:02:07:6d indirizzo inet:192.168.0.11 Bcast:192.168.0.255 Maschera:255.255.255.0 virbr0 Link encap:Ethernet HWaddr fe:54:00:7c:df:88 indirizzo inet:192.168.122.1 Bcast:192.168.122.255 Maschera:255.255.255.0 vnet0 Link encap:Ethernet HWaddr fe:54:00:7c:df:88 indirizzo inet6: fe80::fc54:ff:fe7c:df88/64 Scope:Link 

哪里不对? 或者我可以如何设置一个可见的外部主机?

我前一阵子碰到了这个。 但似乎没有办法在别名界面上设置网桥,如eth0:1 。 使用真实的接口eth0

 auto eth0 iface eth0 inet static auto br0 iface br0 inet static bridge_ports eth0 address 192.168.0.10 netmask 255.255.255.0 gateway 192.168.0.1 broadcast 192.168.0.255 bridge_stp off bridge_fd 0 bridge_maxwait 0 

此外, 地址networking掩码网关广播值是接口应具有的最小configuration。 它可以用更less的值工作,但可能会导致奇怪的networking行为。

正如我还记得,你根本不需要编辑default.xml。 您只需要确保每台KVM Guest都能根据您的需求设置networking接口。

 <interface type='bridge'> <mac address='00:01:b4:02:00:db'/> # change per guest <source bridge='br0'/> # the name of your source bridge <target dev='vnet0'/> # the name, the network interface has for the guest </interface> 

设置是复杂的,以涵盖所有品​​种,如DHCP与静态设置。 你有没有在KVM上看看Ubuntu的文档 ? 帮助我很多,以了解这一点。

为什么不简单地设置客人使用br0? 您可以使用“网桥”对其进行configuration,并将虚拟机连接到br0,而不是将其configuration为“networking”。 例:

 <interface type='bridge'> <source bridge='br0'/> <mac address='00:16:3e:1a:b3:4a'/> </interface> 

这样客户就可以从外部networking获得一个IP,并且可以通过它与主机和主机联系。

注意:但是,使用网桥的缺点是,您将看不到连接到您的虚拟机的客户端IP地址。 相反,桥接主机的IP地址将被logging在Linux虚拟机上的apache,auth.log等中,同样在windows虚拟机中。