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

**URL:** https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486
**Category:** Help
**Created:** [October 17, 2024, 4:04pm UTC](https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486 "2024-10-17T16:04:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![e2g2024pc](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/e/8e7dd6/32.png) [@e2g2024pc](https://discourse.nixos.org/u/e2g2024pc)
#### Post date: [October 17, 2024, 4:04pm UTC](https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486/1 "2024-10-17T16:04:41Z")

</div>

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.

```auto
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?

---

<div class="post-metadata">

### Author: ![johnkyle](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@johnkyle](https://discourse.nixos.org/u/johnkyle)
#### Post date: [October 18, 2024, 9:15pm UTC](https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486/2 "2024-10-18T21:15:36Z")

</div>

> [@e2g2024pc](#):
>
> 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.

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.

---

<div class="post-metadata">

### Author: ![e2g2024pc](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/e/8e7dd6/32.png) [@e2g2024pc](https://discourse.nixos.org/u/e2g2024pc)
#### Post date: [October 20, 2024, 3:51am UTC](https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486/3 "2024-10-20T03:51:54Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![johnkyle](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@johnkyle](https://discourse.nixos.org/u/johnkyle)
#### Post date: [October 21, 2024, 4:43pm UTC](https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486/4 "2024-10-21T16:43:25Z")

</div>

> [@e2g2024pc](#):
>
> 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.

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.

---

<div class="post-metadata">

### Author: ![e2g2024pc](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/e/8e7dd6/32.png) [@e2g2024pc](https://discourse.nixos.org/u/e2g2024pc)
#### Post date: [October 29, 2024, 8:08pm UTC](https://discourse.nixos.org/t/bridge-interface-for-virtio-vms-dymamic-dhcp-for-host-and-for-vms/54486/5 "2024-10-29T20:08:45Z")

</div>

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.

```nix
  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;  

```
