没有为 KVM VM 分配 IPv4 地址

没有为 KVM VM 分配 IPv4 地址

我在 Ubuntu 10.10 中设置 KVM 桥接网络时遇到了麻烦。我通过 virsh 启动虚拟机,之后我可以在主机上看到 kvm 进程和 vnet 设备,但新接口从未获得 IPv4 地址,所以我无法使用虚拟机!以下是虚拟机启动后我可以看到的内容。

root@robin-desktop:~# virsh start meerkat
Domain meerkat started

root@robin-desktop:~# ps aux | grep kvm
root      1411  0.0  0.0      0     0 ?        S    18:20   0:00 [kvm-irqfd-clean]
119       3436 73.7  3.5 1213320 141076 ?      Sl   18:48   0:05 /usr/bin/kvm -S -M pc-0.12 -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name meerkat -uuid dbf905dd-b05d-5c81-5fe4-ad421cd50ece -nographic -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/meerkat.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=utc -boot c -drive file=/home/robin/kvm/meerkat/ubuntu-kvm/tmp6pwohf.qcow2,if=none,id=drive-ide0-0-0,boot=on,format=qcow2 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:06:7e:9c,bus=pci.0,addr=0x3 -net tap,fd=40,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device isa-serial,chardev=serial0 -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
root      3455  0.0  0.0  11340   872 pts/0    S+   18:49   0:00 grep --color=auto kvm
root@robin-desktop:~# 
root@robin-desktop:~# ifconfig 
br0       Link encap:Ethernet  HWaddr e0:cb:4e:bb:99:07  
          inet addr:192.168.1.15  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::e2cb:4eff:febb:9907/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2948 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2904 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1285644 (1.2 MB)  TX bytes:612230 (612.2 KB)

eth0      Link encap:Ethernet  HWaddr e0:cb:4e:bb:99:07  
          inet6 addr: fe80::e2cb:4eff:febb:9907/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3835 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3845 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1817408 (1.8 MB)  TX bytes:785533 (785.5 KB)
          Interrupt:47 Base address:0x2000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:63 errors:0 dropped:0 overruns:0 frame:0
          TX packets:63 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:4869 (4.8 KB)  TX bytes:4869 (4.8 KB)

vnet0     Link encap:Ethernet  HWaddr fe:54:00:06:7e:9c  
          inet6 addr: fe80::fc54:ff:fe06:7e9c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:4137 (4.1 KB)

root@robin-desktop:~#

稍微挖掘一下,守护进程日志文件中可能会出现一些线索:

root@robin-desktop:~# tail -7 /var/log/daemon.log
Dec  1 18:48:55 robin-desktop NetworkManager[3342]:    SCPlugin-Ifupdown: devices added (path: /sys/devices/virtual/net/vnet0, iface: vnet0)
Dec  1 18:48:55 robin-desktop NetworkManager[3342]:    SCPlugin-Ifupdown: device added (path: /sys/devices/virtual/net/vnet0, iface: vnet0): no ifupdown configuration found.
Dec  1 18:48:55 robin-desktop NetworkManager[3342]: <warn> /sys/devices/virtual/net/vnet0: couldn't determine device driver; ignoring...
Dec  1 18:48:55 robin-desktop modem-manager: (net/vnet0): could not get port's parent device
Dec  1 18:48:56 robin-desktop avahi-daemon[3354]: Joining mDNS multicast group on interface vnet0.IPv6 with address fe80::fc54:ff:fe06:7e9c.
Dec  1 18:48:56 robin-desktop avahi-daemon[3354]: New relevant interface vnet0.IPv6 for mDNS.
Dec  1 18:48:56 robin-desktop avahi-daemon[3354]: Registering new address record for fe80::fc54:ff:fe06:7e9c on vnet0.*.

我尝试关闭 avahi 和网络管理器 - 没有区别。

有人遇到过类似的问题吗?我在 Ubuntu 9.10 上用这个东西运行正常!

谢谢。

编辑:这是一些 brctl 输出:

root@robin-desktop:~# brctl 显示

bridge name bridge id       STP enabled interfaces
br0     8000.e0cb4ebb9907   no      eth0
                            vnet0

编辑 2:这是主机上的网络接口文件

robin@robin-desktop:~$ cat /etc/network/interfaces 
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet dhcp
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0

我应该设置吗bridge_stp on

编辑3:这是 libvirt xml 配置,它最初是由 ubuntu-vmbuilder 创建的,我对它进行了一些修改

<domain type='kvm'>
  <name>meerkat</name>
  <uuid>dbf905dd-b05d-5c81-5fe4-ad421cd50ece</uuid>
  <memory>1048576</memory>
  <currentMemory>1048576</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-0.12'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/robin/kvm/meerkat/ubuntu-kvm/tmp6pwohf.qcow2'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
    </disk>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:06:7e:9c'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </memballoon>
  </devices>
</domain>

答案1

-A FORWARD -m physdev --physdev-is-bridged -j ACCEPT 在 /etc/sysconfig/iptables 中,我添加了此行以使我的 kvm 正常工作。

答案2

请检查您的防火墙主机中的设置。我曾经被这个问题困扰过——花了好几个小时才找到问题所在。虚拟机必须能够通过网桥发送和接收 dhcp 数据包通过主机防火墙规则再次返回。

答案3

我使用静态地址在虚拟机上定义接口/etc/network/interfaces。虚拟机需要使用以太网接口进行定义。vnet在服务器上为虚拟机创建的设备。vnet接口应在服务器上显示为未定义地址的 up。设备将作为vm 上的接口类型 vnet出现。eth

如果以上输出是针对您的服务器的,则br0服务器上的地址应该适用于虚拟机。 eth0服务器上应该有外部访问所需的任何地址。您还应该有一个vnet0我没看到的设备。

编辑:我还通过 virsh 关闭了网络的自动启动。这是我的其中一座网桥的 /etc/network/initerfaces 定义。我相应地更新了我的 dhsmasq 配置。

自动virbr0
iface virbr0 inet 静态
        地址 192.168.10.1
        网络掩码 255.255.255.224
        预先 brctl addbr virbr0
        停机后 brctl delbr virbr0

匹配网络定义是

<网络>
  <名称>默认</名称>
  <uuid>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</uuid>
  <bridge 名称='virbr0' stp='on' forwardDelay='0' />
  <域名='virt.example.com'/>
</网络>

相关内容