4

I need to create a persistent network bridge for Virtual machines (libvirt)

So this bridge does not need any physical ports, connections will be routed for this bridge.

If I set this up manually, it works as I described. However I can't get this to persist between reboots.

I have created the bridge in /etc/network/interfaces:

 auto vm-bridge
  iface vm-bridge inet static
   address 10.1.0.1
   broadcast 10.1.0.3
   netmask 255.255.255.252
   gateway 10.1.0.1

However the interface is not created when the host reboots. All reference on the internet are adding bridge_ports to the bridge, so I'm not sure what I'm missing.

2 Answers2

5

You have to give an option so the bridge plugin that is provided as /etc/network/if-pre-up.d/bridge by installing the package bridge-utils activates. The main command it provides brctl is of no use (superseded by ip link + bridge), but the plugin does matter. Without a bridge-related option, the system has no way to understand a bridge has to be created. So if using the package ifupdown (rather than ifupdown2 or ifupdown-ng):

apt install bridge-utils

Then the simplest option for this is to tell it there is no bridge port. Add this option:

bridge_ports none

which will now activate the plugin and create a bridge and as requested with the special keyword none will not attach any interface as bridge port to it.

Remarks:

  • there is one default route to be used at the same time

      gateway 10.1.0.1
    

    is probably a mistake: if you already have an other default route on the system (also with metric 0), this will make the result fail. This is especially true when designating oneself as the gateway. Remove it first (as I did below), and ponder adding it again later.

  • a bridge without bridge port is in operstate DOWN

    ... on any recent system running a recent systemd such as Debian 11 or 12.

    As described for example in this Q/A with the cause described for example in my answer in this Q/A. This can cause a few issues for IPv6, but usually none for IPv4.

The configuration becomes:

auto vm-bridge
iface vm-bridge inet static
   address 10.1.0.1
   broadcast 10.1.0.3
   netmask 255.255.255.252
   # gateway 10.1.0.1
   bridge_ports none
A.B
  • 13,968
1

Note that as commenters pointed out this answer is based on specific version of Debian Bookworm from cloud image. For the usual version of Debian other answer holds.

Assuming you are using Debian Bookworm, it doesn't obey /etc/network/interfaces anymore by default, since it uses systemd-networkd.

To create bridge add file vm-bridge.netdev to /etc/systemd/network/:

[NetDev]
Name=vm-bridge
Kind=bridge

Now we need to configure network for this bridge. Create file /etc/systemd/network/vm-bridge.network:

[Match]
Name=vm-bridge

[Network] Address=10.1.0.1/30 Gateway=10.1.0.1

And then restart networkd:

systemctl restart systemd-networkd

Refer to docs for more information. For specific configuration there is detailed guide on Arch wiki.