linux – 适当的网络配置,使KVM来宾位于主机的同一网络上

我在Lenny上运行Debian Linux服务器.在其中,我正在使用KVM运行另一个Lenny实例.两个服务器都是外部可用的,具有公共IP,以及第二个具有LAN专用IP的接口.一切正常,但VM将所有网络流量视为源自主机服务器.我怀疑这可能与我在主机上运行的基于iptables的防火墙有关.

我想弄清楚的是:如何正确配置主机的网络,以满足所有这些要求?

>主机和VM都有2个网络接口(公共和私有).
>主机和VM都可以独立防火墙.
>理想情况下,VM流量不必遍历主机防火墙.
>虚拟机可以看到真正的远程IP地址,而不是主机.

目前,主机的网络接口配置为网桥. 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 / qemu配置文件:

<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来宾的数据包:

# Allow bridged packets to pass (for KVM guests).
iptables -A FORWARD -m physdev --physdev-is-bridged -j ACCEPT

(不适用于这个问题,但我的桥接配置的副作用似乎是我不能干净地关闭.内核最终告诉我“unregister_netdevice:等待br1变得自由”而且我必须硬复位系统.也许是一个我做过蠢事的标志?)

解决方法

您将VM桥接到错误的接口.它们应桥接到连接到外部世界的网络接口(在您的情况下为br1).

请记住,每个VM还应在guest虚拟机中设置其IP地址,而不是在主机上设置.

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...