Bridged networking for KVM on laptop?

Hi,

I’m running Rocky Linux 8 on my Dell XPS laptop which has only a wireless card. The corresponding interface is wlp2s0.

In the past I’ve used VirtualBox on this laptop, and I could manage bridged VMs with it, e. g. virtual machines could be installed on the same network and reached from the outside.

Now I’m trying to do a similar thing with KVM/libvirt and I’m currently banging my head on the keyboard. I know how to setup a bridged interface like br0 with nmtui on a machine with a wired Ethernet card. But I can’t seem to wrap my head around the same thing on a wireless card.

Here’s what I want to achieve.

  1. Laptop’s not always connected to an access point.

  2. When it connects to the Internet, dynamically create a bridge br0 with wlp2s0 as bridge slave.

  3. Wipe the bridge when disconnecting from an access point.

Any idea if this is possible and how I can achieve it ?

Disclaimer: I have not used wireless.

A bridge can exists without any ports. The host could have a bridge that is always there, whether you have link and libvirt or not. The VM’s will be detached to the bridge.

If wireless interfaces behave like wired and the wlp2s0 is enslaved to the bridge, then on connection to access point the DHCP clients of the host and VMs should be able to reach DHCP server on the subnet and gain IP config for the bridge and the VMs, respectively.

Alas, then the bridge would exists all the time and not be “spawn and wiped”.

The man nmcli-examples essentially shows bridge setup as:

$ nmcli con add type bridge con-name TowerBridge ifname TowerBridge bridge.stp no
$ nmcli con add type ethernet con-name br-slave-1 ifname ens3 master TowerBridge

Note that the bridge is defined first, because its identifier has to be supplied to the ethernet connection in order to prevent the ethernet connection having ‘ipv4’ and ‘ipv6’ sections. It is possible to edit existing connection config to enslave it to bridge.

1 Like

From the Debian link: BridgeNetworkConnections - Debian Wiki

The link does give commands for pre-up to connect the wifi card to the SSID, but you then need to assign your wifi MAC to the bridge (br0), that way any traffic over the bridge, looks like it’s coming from your already-authenticated laptop. So there should be a way to do this - maybe enough to create the bridge and assign the same MAC as the wifi card. But may require re-activating the bridge once the wifi has reconnected itself unless Rocky/RHEL does allow a similar way like with Debian.

VirtualBox was most likely doing this without you knowing about it just by simply choosing the option in the VirtualBox network config.

Far easier to do over an ethernet cable to be honest, less hassle and problems to worry about than with wifi.

1 Like