#!/bin/bash # configure-bridge.sh # This script configures a network bridge interface for KVM on Arch Linux # using systemd-networkd. It creates configuration files for: # - the bridge interface (default: br0) # - the physical interface to be enslaved to the bridge # # Usage: # sudo ./configure-bridge.sh [bridge_name] # # Example: # sudo ./configure-bridge.sh enp2s0 br0 # # Reference: Arch Linux Wiki, "Bridge networking" https://wiki.archlinux.org/title/Bridge_networking set -euo pipefail if [ "$EUID" -ne 0 ]; then echo "Please run as root." exit 1 fi if [ "$#" -lt 1 ]; then echo "Usage: $0 [bridge_name]" exit 1 fi PHYS_IF="$1" BRIDGE_IF="${2:-br0}" NETWORK_DIR="/etc/systemd/network" if [ ! -d "$NETWORK_DIR" ]; then echo "Directory $NETWORK_DIR does not exist. Please ensure systemd-networkd is installed." exit 1 fi echo "Configuring bridge interface '${BRIDGE_IF}' for physical interface '${PHYS_IF}'..." # Create the .netdev file for the bridge BRIDGE_NETDEV_FILE="${NETWORK_DIR}/25-${BRIDGE_IF}.netdev" cat > "$BRIDGE_NETDEV_FILE" < "$BRIDGE_NETWORK_FILE" < "$PHYS_NETWORK_FILE" <