I've installed qemu and virt manager on Arch but keep getting errors when installing virtual machines:
There is no virtbr0 when running ip addr show
when I first start my system, running virsh net-list --all
also shows nothing. I have searched for some solutions and found to disable dnmasq and some other commands which I fed into chat gpt to get a script:
#!/bin/bash # Variables NETWORK_XML="/etc/libvirt/qemu/networks/default.xml" RESOLV_CONF="/etc/resolv.conf" BRIDGE_NAME="br0" MAIN_INTERFACE="eth0" # Replace with your primary interface (e.g., eth0, ens33) # Function to check if a service is running is_service_running() { systemctl is-active --quiet "$1" } # Function to stop conflicting services if they are running stop_conflicting_services() { echo "Checking for conflicting services..." # Stop systemd-resolved (if running) if is_service_running systemd-resolved; then echo "Stopping systemd-resolved..." sudo systemctl stop systemd-resolved sudo systemctl disable systemd-resolved # Ensure resolv.conf is not a symlink sudo rm -f "$RESOLV_CONF" echo "nameserver 8.8.8.8" | sudo tee "$RESOLV_CONF" > /dev/null fi # Check if dnsmasq is already running (if needed for libvirt) if is_service_running dnsmasq; then echo "Stopping conflicting dnsmasq instance..." sudo systemctl stop dnsmasq fi # Do NOT disable NetworkManager unless necessary if is_service_running NetworkManager; then echo "NetworkManager is running. Not disabling it to avoid disconnecting you." fi } # Function to create and define the libvirt default network create_default_network() { echo "Creating default.xml for virtbr0 network..." # Create default.xml content cat <<EOF | sudo tee "$NETWORK_XML" > /dev/null <network> <name>default</name> <forward mode="nat"/> <bridge name="$BRIDGE_NAME"/> <ip address="192.168.122.1" netmask="255.255.255.0"> <dhcp> <range start="192.168.122.2" end="192.168.122.254"/> </dhcp> </ip> </network> EOF # Define, start, and enable the network sudo virsh net-define "$NETWORK_XML" sudo virsh net-start default sudo virsh net-autostart default } # Function to ensure proper libvirtd startup enable_libvirtd() { echo "Enabling libvirtd to start on boot..." sudo systemctl enable --now libvirtd } # Function to create a persistent bridge using systemd-networkd create_persistent_bridge() { echo "Creating a persistent bridge with systemd-networkd..." # Create bridge configuration file sudo bash -c 'cat <<EOF > /etc/systemd/network/10-br0.netdev [NetDev] Name=br0 Kind=bridge EOF' sudo bash -c 'cat <<EOF > /etc/systemd/network/10-br0.network [Match] Name=br0 [Network] DHCP=ipv4 EOF' # Create interface configuration to add the main interface to the bridge sudo bash -c "cat <<EOF > /etc/systemd/network/10-${MAIN_INTERFACE}.network [Match] Name=${MAIN_INTERFACE} [Network] Bridge=br0 EOF" # Restart systemd-networkd to apply the changes sudo systemctl restart systemd-networkd } # Start the process stop_conflicting_services create_default_network create_persistent_bridge enable_libvirtd echo "Configuration complete. 'default' network should now be active and set to autostart."
this sort of fixes the problem, now i sometimes get virtbr0 and default when running ip addr show
and net-list --all
respectively.
The problem with this is, when this is working I can get virtual machines to install: I've installed both Rocky linux, which created with an IP of 10.0.5.2 and I could not reach when pinging or ssh-ing from the host machine, and a Debian machine which created with the IP of 192.168.122.51 which could be reached. (I was trying to ssh as I have been trying to write postgresSQL install scripts and want to get it working separate from my host machine). The connections also dissapear again at seemingly random intervals and if I rerun the script without rebooting my machine it doesn't work.
I'm not great at networking and need to know how I can I get these settings to persist so i can reach my virtual machines and how to get Rocky linux and others, (would all RHEL based distros be the same?) to connect in such a manner they can be reachable.
NETWORK_XML
. The IP is never set because for RedHat the script is looking in the wrong place, as such,virt
defaults the configuration to10.x.x.x
Have a look at setting up virt for Fedora, as Fedora is RedHat's Open Source child.