Kvm bridge mode guest os can't get ip

hello,everyone,I am using Rockylinux9.
I created kvm bridge mode on Rockylinux 9,but guest os can’t get ip address.What should I do?
please help me,thanks!

You need to ensure that libvirt has your bridge interface and that you have configured your bridge and its underlying interface correctly with nmcli. When your VM is connected to the bridge (properly), vnet interfaces are supposed to appear in both nmcli c s and ip a.

In some instances, you may need to also set net.ipv4.ip_forward=1 in /etc/sysctl.d/99-sysctl.conf and sysctl -w net.ipv4.ip_forward=1. But this only matters once the bridge and libvirt are properly configured.

1 Like

Thanks,centos7,8 create kvm bridge mode ,do not enable ip_forward.So can you tell me why do rockylinux’s kvm bridge need enable ip_forward?

That isn’t what I said. I said in some instances you may need it. You need to address the other problem, which is no vnet interfaces are appearing, which tells me you have KVM and the network bridges misconfigured.

sir,now it screens vnet0 interface

still can’t get ip address.
I created kvm bridge mode on Rockylinux 9 like this
1.nmcli connection add con-name br0 type bridge autoconnect yes ipv4.method auto ifname br0
2.nmcli connection add con-name bridge0 autoconnect yes type ethernet slave-type bridge ifname enp1s0 master br0
3.nmcli connection down ‘有线连接 1’ && nmcli connection up br0
4.systemctl enable --now libvirtd.socket
5.virsh start winxp

Name “bridge0” for ethernet port is a bit confusing. On first glance I thought that you have two bridges: “br0” and “bridge0”. That is not an error though.

Do run tcpdump on the host to listen on the interface ‘br0’. For example:

tcpdump -n -v -i br0

(If the host or outside subnet has lots of traffic, then you have to add a filter rules.)

Restart the VM while you do listen. The DHCP requests from the guest should show up on the bridge, and replies to them from the DHCP server that you have in the outside subnet. Options are:

  • Windows does not send requests that would reach the bridge
  • Windows does send, but server does not respond
  • Windows does send, but server responds “no”

One can also listen on interfaces enp1s0 and vnet0. (If you shut down the VM, then vnet0 disappears, but if you just reboot the XP, then the interface stays up for tcpdump to listen on.)

Thanks,sir.I tried to using tcpdump,listening br0,It looks no dhcp server.guets os still couldn’t to get ip address

Do you see the DHCP request also on the enp1s0 interface? (The bridge should send it out from that “port”.)

You do have a DHCP server that would hand an IP address for that MAC of VM, don’t you?


PS. You have networking on the host, so you could copy-paste the command outputs, rather than taking photos.

Thanks,sir.Now I,ve fixed the dhcp server,guest os can get ip address,but guest os can’t ping gateway

You show:

  • router: 192.168.1.1
  • host: 192.168.1.4
  • guest: 192.168.1.5
  • host can ping “x.com
  • guest can ping host
  • guest cannot ping router
  • br0 has STP on

First STP, Spanning Tree Protocol, is used by switches to detect and prevent loops. There will be no loop in here (unless you explicitly create such), so the STP can be set off.
nmcli con mod br0 bridge.stp no

Second, you don’t show whether:

  • host can ping the router
  • guest can ping the x.com
    (it is possible that a router is set to not reply on pings.)

You had Windows XP guest. Now you have CentOS 7 guest?

sir,guest can’t ping the router.but the host can ping the router
host can ping x.com,guest can’t ping x.com. One host(Rockylinux),Two Guests(Win xp,Centos7).

First of all, I would not recommend if you install linux in Chinese, as in some terminal emulators, the Chinese character would display as tofu.
Secondly, the virbr0 is default bridge for your vms in libvirt, while the br0 is a linux bridge. bridge0 is a connection to your ethernet device enp1s0.
I understand that you want to make your VMs connect directly to enp1s0. In this case, you should do as follows:

  1. make a new bridge with nmcli. linuxbr1 for example. make your enp1s0 the uplink for the new bridge.
    test your host connection to the internet.
  2. configure the new bridge as the default bridge for libvirt.
    test your vm configuration ti the internet. take the following as a brief example
<network>
  <name>default</name>
  <forward mode='bridge'/>
  <bridge name='linuxbr1'/>
</network>
  1. remove unused configurations.

Most likely vnet interface associated with your guest vm is not linked to the bridge