QEMU Bridge setup - Maybe already known but I found it pretty difficult to do and needed much reading

My setup of a qemu bridge called by systemd service at host boot up, and allows System created VMs in VMM to use the same subnet as physical host.

This might be rubbish programmatically, but it works, and there may be too much in the scripts, but I wanted belt ‘n’ braces.

Below service script.

1st argument = ethernet adapter device name.

2nd argument = bridge name.

3rd argument = first three octets of current network.

Put this in /lib/systemd/system/ModifyNWforQemuBridge.service

[Unit]Description=Startup Script
[Service]ExecStart=/usr/bin/bash -c ‘/usr/local/bin/ModifyNWforQemuBridge.bsh enp2s0 VMMbr0 192.168.2’
[Install]WantedBy=multi-user.target

Put this in /usr/local/bin/ModifyNWforQemuBridge.bsh

#!/usr/bin/env bash
INTERFACE=“$1”BRIDGE=“$2”NETWORK=“$3”LOGFILE=“/var/log/ModifyNWforQemuBridge.bsh.log”
pkey_up_func() {
#We wait for 5 mins (300 secs) to detect NetworkManager startup.

nm-online --wait-for-startup --timeout 300
status=$?
if [[ “$status” == “0” ]]; then
echo “$0: nm-online detected that NetworkManager has completed start-up.” > $LOGFILE
#Clear out any earlier bridge setup
nmcli con delete bridge-slave-$INTERFACE 2>&1 >> $LOGFILE
nmcli con down $BRIDGE 2>&1 >> $LOGFILE
nmcli con delete $BRIDGE 2>&1 >> $LOGFILE
sleep 2
nmcli con add ifname $BRIDGE type bridge con-name $BRIDGE >> $LOGFILE
nmcli con add type bridge-slave ifname $INTERFACE master $BRIDGE >> $LOGFILE
nmcli con mod $BRIDGE bridge.stp no >> $LOGFILE
nmcli con down $INTERFACE >> $LOGFILE
nmcli con mod $BRIDGE ipv4.addresses $NETWORK.3/24 >> $LOGFILE
nmcli con mod $BRIDGE ipv4.gateway $NETWORK.1 >> $LOGFILE
#nmcli con mod $BRIDGE ipv4.dns $NETWORK’.1’ >> $LOGFILE
nmcli con mod $BRIDGE ipv4.dns ‘1.1.1.1,1.0.0.1’ >> $LOGFILE
nmcli con mod $BRIDGE ipv4.dns-search ‘``example.com``’ >> $LOGFILE
nmcli con mod $BRIDGE ipv4.method manual >> $LOGFILE
nmcli con mod $BRIDGE ipv6.method “disabled”
nmcli con up $BRIDGE >> $LOGFILE

`elif [[ "$status" == "1" ]]; then             echo "$0: nm-online timeout exceeded while attempting to detect NetworkManager startup." > $LOGFILE     else             echo "$0: nm-online encountered an unexpected error." > $LOGFILE     fi`
}

#Put things back to my normal before doing anything:sudo /usr/bin/bash -c “systemctl  enable systemd-resolved.service --now && sed -i ‘/^nameserver/c\nameserver $NETWORK.1’ /etc/resolv.conf”

#Execute this script to setup the bridge and to make 1.1.1.1,1.0.0.1 the dns resolver IP.

pkey_up_func

Enable and start the systemd service by:

systemctl enable ModifyNWforQemuBridge.service –now

I think networkManager will save this across reboots so perhaps the service does not need to be enabled or used at all, and the /usr/local/bin script can be manually executed with your three arguments.

Hello,

You might want to make use of coding brackets or tics to enclose formatted text, ex;

I am trying to do just that :slight_smile:

Thank you.

This should just work out of the box. I am wondering why this is always so much pain :joy:
A lot articles tell to use bridge-utils , even articles about Arch, but this package is not even existing :person_facepalming:

Not sure how necessary it actually is ..

But that package exists in the AUR.

Since bridge-utils is deprecated, consider ip or nmcli if the AUR isn’t your thing.