Bridge interface for virtio vms - dymamic dhcp for host and for vms

I am using kvm via virt-manager to run some VMs. I wanted to use a bridge instead of the default NAT to make access a bit easier.

I was able to get the bride running and then I could remote directly into the VM I was running. However, when I went back at the host level to try to do something with the network it failed.

When I ran ip a I saw that the actual hardware interface enp9s0 was not assigned an IP address.

I am using the following to create the bridge.

networking.bridges = {
    "vmbr0" = {
      interfaces = [ "enp9s0" ];  # Replace with your actual physical interface
    };
  };

If I modified my config and removed the networking.bridges directive, the bridge of course went away, but then I had an IP assigned on enp9s0.

I tried some various options like
networking.dhcpcd.denyInterfaces = [ "vmbr0" ];

or other DHCP related command trying to enable to disable for both the physical and virtual, but it didn’t seem to do what I want.

I found other posts where it looks like they want the host to use static while the guest vms use dynamic.

Is it not possible to use DHCP for both guest and hosts or do I need to somehow configure to go through the bridge from the host as well?

But that part’s normal. The IP address gets assigned on the bridge device, vmbr0 in your case. When your VM isn’t up, it can be a bridge containing one device only.

@johnkyle - To clarify, I still need an IP address at the host level.

There is no IP assigned to the bridge device on the host level. The VM gets a DHCP address.

What needs to happen to get an network connection and IP address on the host outside the VM. e.g., I still would need to do management outside of the VM.

Are you saying the expectation is that once the bridge is created there is no way to have host level network access. My understanding was that your physical card still listens for its own commands.

I don’t recall having this problem with window using something like virtualbox in the past, but its been much longer since I’ve done something like this in Linux. I haven’t come across anything else describing a problem like this.

Yes, that’s correct. Set up your host configuration to get an IP for vmbr0 (you might want to remove the vm prefix, since it will be your host’s main interface with this setup, regardless of VMs).

The guest has its own virtual network interface, so it acts like a whole other device on the same network. This distinction is confusing, because it’s not the same thing as bridging within a single host. The VM has its own network identity based off of its virtual MAC address, so it can use DHCP itself and get another IP. You can’t do this with multiple physical interfaces bridged together on the same host.

I think I left this out in the first post, but the vmbr0 was ALSO not receiving an IP address.

In some searching I found something about disabling all DHCP then enabling it just where needed. With this config below I am able to get Internet on my host and in all my VMs. Not sure if I really need to enable DHCP on the physical device, but didn’t want to mess with anything.

  networking.networkmanager.enable = false;
  networking.useDHCP = false;  # Enable DHCP for the host
  networking.bridges = {
    "br0" = {
      interfaces = [ "enp9s0" ];  # Replace with your actual physical interface
    };
  };
  networking.interfaces.br0.useDHCP = true;
  networking.interfaces.enp9s0.useDHCP = true;