KVM 桥接网络:虚拟机缺少 IPv4

KVM 桥接网络:虚拟机缺少 IPv4

操作系统:Ubuntu 16.04.3

在我的以太网卡(eno1)、客户机(vnet0)和网桥(br0)之间配置 KVM 桥接器

我的网桥与网卡正常工作,以便我的机器可以通过 WAN 访问路由器。

我一直遵循这些指南:

https://jamielinux.com/docs/libvirt-networking-handbook/bridged-network.html

没有为 KVM VM 分配 IPv4 地址

https://wiki.debian.org/BridgeNetworkConnections

以下是 br0 的接口设置:#ifup(8) 和 ifdown(8) 使用的接口(5)文件 auto lo iface lo inet loopback

# Ethernet
iface eno1 inet manual

# Bridge
auto br0 
iface br0 inet static
        hwaddress ether 40:16:7e:28:0e:60
        address 192.168.1.200
        netmask 255.255.255.0
        network 192.168.1.0
        gateway 192.168.1.254
        broadcast 192.168.1.255

        bridge_ports eno1
        bridge_stp off 
        bridge_fd 0

        dns-nameservers 192.168.1.254 8.8.8.8 8.8.8.4

当被提起时:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 40:16:7e:28:0e:60 brd ff:ff:ff:ff:ff:ff
3: wlp13s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 54:27:1e:97:32:16 brd ff:ff:ff:ff:ff:ff
53: vboxnet0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
82: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:53:24:54:a5 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 scope global docker0
       valid_lft forever preferred_lft forever
181: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 40:16:7e:28:0e:60 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.200/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 2001:569:737d:a300:4216:7eff:fe28:e60/64 scope global mngtmpaddr dynamic 
       valid_lft 14700sec preferred_lft 14400sec
    inet6 fe80::4216:7eff:fe28:e60/64 scope link 
       valid_lft forever preferred_lft forever
182: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN group default qlen 1000
    link/ether fe:57:13:a9:fb:22 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fc57:13ff:fea9:fb22/64 scope link 
       valid_lft forever preferred_lft forever

最后我在 /etc/sysctl.d/bridge.conf 中找到了它

net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-iptables=0
net.bridge.bridge-nf-call-arptables=0

重新加载:

sysctl -p /etc/sysctl.d/bridge.conf

好的,在虚拟机方面,我正在使用带有 libvirt 提供程序的 terraform https://github.com/dmacvicar/terraform-provider-libvirt

我不会展示 terraform 文件,因为它超出了范围,但它生成的 xml 就是这样。

<domain type='kvm' id='40'>
  <name>ubuntu1</name>
  <uuid>4bd33601-b6a1-4863-a230-8b3ea4dfa48c</uuid>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-xenial'>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>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/ubuntu-qcow2'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/commoninit.iso'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <alias name='virtio-serial0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='ea:57:13:a9:fb:22'/>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/18'/>
      <target type='isa-serial' port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/18'>
      <source path='/dev/pts/18'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <console type='pty'>
      <source path='/dev/pts/19'/>
      <target type='virtio' port='1'/>
      <alias name='console1'/>
    </console>
    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-ubuntu1/org.qemu.guest_agent.0'/>
      <target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' port='5900' autoport='yes'>
      <listen type='address'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/random</backend>
      <alias name='rng0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </rng>
  </devices>
  <seclabel type='dynamic' model='apparmor' relabel='yes'>
    <label>libvirt-4bd33601-b6a1-4863-a230-8b3ea4dfa48c</label>
    <imagelabel>libvirt-4bd33601-b6a1-4863-a230-8b3ea4dfa48c</imagelabel>
  </seclabel>
</domain>

一旦虚拟机启动并运行,将ip addr返回以下内容:

brctl 显示:

bridge name bridge id       STP enabled interfaces
br0     8000.40167e280e60       no             eno1
                                              vnet0
docker0     8000.0242532454a5   no      

并且 virsh addrs 没有显示任何可供我连接的接口:

> virsh domifaddr ubuntu1 vnet0
 Name       MAC address          Protocol     Address
-------------------------------------------------------------------------------

我希望根据与路由器的桥接连接填充 IP 地址。我的家用路由器为主机预留了 dhcp,但我希望访客也能获得 IP?

如能提供关于如何在 LAN 上获取虚拟机 IP 的指导,我们将不胜感激。

相关内容