QEMU 和 TAP 接口的桥上没有 DHCP 回复

QEMU 和 TAP 接口的桥上没有 DHCP 回复

我有一台使用 QEMU 运行虚拟机的主机,我希望主机上的 DHCP 服务器为其提供一个 IP 地址。

我为客人使用了静态以太网地址,因此我像这样启动它们:

qemu-system-x86_64 -hda debian.img -netdev tap,id=n1,ifname=tap0001,script=/root/qemu/net-up.sh,downscript=/root/qemu/net-down.sh -device virtio-net-pci,netdev=n1,mac=02:00:00:01:01:01 -enable-kvm -cdrom /root/qemu/install-amd64-minimal-20180802T214502Z.iso -boot d -enable-kvm -qmp tcp:localhost:4444,server,nowait -smp 2,cores=16,threads=1,sockets=2,maxcpus=32 -m size=1G -vnc :1

因为我想通过数据库管理主机预留,所以我使用带有 MySQL Backend 的 Kea DHCP 服务器。

启动虚拟机后,我有以下网络设置:

Host:
eno1: 10.0.0.1 (listening for dhcp requests)
tap0001: no IP (TAP interface for the VM)
br00001: no IP (bridges tap0001 and eno1)

Guest:
eth0: hw ether 02:00:00:01:01:01

现在,当我从主机请求 IP 时,我可以看到 Kea 提供配置的 IP:

2018-08-15 23:13:46.536 INFO  [kea-dhcp4.leases/6548] DHCP4_LEASE_ADVERT [hwtype=1 02:00:00:01:01:01], cid=[ff:00:01:01:01:00:01:00:01:23:07:53:2b:02:00:00:01:01:01], tid=0xf069f396: lease 10.0.0.10 will be advertised
2018-08-15 23:14:51.444 INFO  [kea-dhcp4.leases/6548] DHCP4_LEASE_ADVERT [hwtype=1 02:00:00:01:01:01], cid=[ff:00:01:01:01:00:01:00:01:23:07:53:2b:02:00:00:01:01:01], tid=0xf069f396: lease 10.0.0.10 will be advertised

我还可以看到 eno1 上的 DHCP 发现和答复:

tcpdump port 67 or port 68 -i eno1 -nN
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eno1, link-type EN10MB (Ethernet), capture size 262144 bytes
23:11:41.326945 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 02:00:00:01:01:01, length 356
23:11:41.329444 IP 10.0.0.1.67 > 10.0.0.10.68: BOOTP/DHCP, Reply, length 307

但是在 br0001 和 tap0001 上都看不到 DHCP Reply:

tcpdump port 67 or port 68 -i br0001 -nN
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br0001, link-type EN10MB (Ethernet), capture size 262144 bytes

23:26:33.308296 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 02:00:00:01:01:01, length 356
23:26:37.336875 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 02:00:00:01:01:01, length 356

有人能给我指出正确的方向吗,以便将 DHCP 回复发送到 VM。谢谢。

答案1

看来您已将您的 IP 分配给 eno1。

一般来说,如果您使用网桥,您的 IP 应该分配给网桥本身,而不是您添加到网桥的第一个接口。

https://unix.stackexchange.com/questions/86056/why-does-linux-require-moving-ip-from-eth-interface-to-bridge-interface

相关内容