我在Lenny上运行Debian Linux服务器。 在其中,我正在运行另一个使用KVM的Lenny实例。 这两台服务器都可以在外部使用,使用公共IP,也可以使用第二个带有局域网私有IP的接口。 一切工作正常,除了虚拟机看到所有的networkingstream量源自主机服务器。 我怀疑这可能与我在主机上运行的基于iptables的防火墙有关。
我想弄清楚的是:如何正确configuration主机的networking,以满足所有这些要求?
目前,主机的networking接口被configuration为网桥。 eth0和eth1没有分配给它们的IP地址,但是br0和br1做的。
主机上的/etc/network/interfaces :
# The primary network interface auto br1 iface br1 inet static address 24.123.138.34 netmask 255.255.255.248 network 24.123.138.32 broadcast 24.123.138.39 gateway 24.123.138.33 bridge_ports eth1 bridge_stp off auto br1:0 iface br1:0 inet static address 24.123.138.36 netmask 255.255.255.248 network 24.123.138.32 broadcast 24.123.138.39 # Internal network auto br0 iface br0 inet static address 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 bridge_ports eth0 bridge_stp off
这是VM的libvirt / qemuconfiguration文件:
<domain type='kvm'> <name>apps</name> <uuid>636b6620-0949-bc88-3197-37153b88772e</uuid> <memory>393216</memory> <currentMemory>393216</currentMemory> <vcpu>1</vcpu> <os> <type arch='i686' machine='pc'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='cdrom'> <target dev='hdc' bus='ide'/> <readonly/> </disk> <disk type='file' device='disk'> <source file='/raid/kvm-images/apps.qcow2'/> <target dev='vda' bus='virtio'/> </disk> <interface type='bridge'> <mac address='54:52:00:27:5e:02'/> <source bridge='br0'/> <model type='virtio'/> </interface> <interface type='bridge'> <mac address='54:52:00:40:cc:7f'/> <source bridge='br1'/> <model type='virtio'/> </interface> <serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target port='0'/> </console> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/> </devices> </domain>
除了我的其他防火墙规则之外,防火墙脚本还包含此命令来传递指定给KVM guest虚拟机的数据包:
# Allow bridged packets to pass (for KVM guests). iptables -A FORWARD -m physdev --physdev-is-bridged -j ACCEPT
(不适用于这个问题,但桥接configuration的副作用似乎是我不能干净地closures内核最终告诉我“unregister_netdevice:等待br1变得自由”,我必须硬重置系统,也许我做了一些愚蠢的标志?)
您将虚拟机桥接到错误的界面。 他们应该桥接到连接到外部世界的networking接口(在你的情况下是br1 )。
请记住,每台虚拟机的IP地址也应该设置在guest虚拟机上, 而不是主机上。
为什么你需要br1:0的别名? 这可能是在那里的方式
除了别名,这个想法是使用以下scheme:
eth0-> br0 < – VM的tap设备
主机应该能够使用br0,因为它是中频,虚拟机将使用tap设备作为插入虚拟交换机的虚拟网卡(br0有效地变成了这里)
当然每个networking都是一样的,所以对于eth1,你必须build立一个br1,然后把虚拟机插入br1
我有一个使用lib-virt和virtio桥接到br0(不使用br1或br0:0)的Lenny主机中Lenny / Squeeze VM的相同设置。 它工作正常,没有任何特殊的iptablesconfiguration在主机上。 我在每个访客虚拟机中执行所有防火墙configuration。
我认为你可能从检查networking路由中获益,看看你的虚拟机是否使用主机作为网关。 Mine被configuration为使用外部路由器作为网关。 当然,我的虚拟机和主机在同一个范围内的不同的IP地址。