Created
January 5, 2023 03:06
-
-
Save scresante/c820073771301eac83ce17959f4c5679 to your computer and use it in GitHub Desktop.
configure_bridge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this script will set up a bridge in a libvirt host that has network manager | |
if [ -z $1 ] || [ -z $2 ] || [[ $1 = -h ]] || [[ $1 = --help ]]; then | |
echo "Usage: $0 [interface] [activate|deactivate]" | |
exit 1 | |
fi | |
IFACE=$1 | |
if ! command -v nmcli &> /dev/null ; then | |
echo this script requires nmcli to be installed | |
exit 2 | |
fi | |
con=`nmcli -t -m tabular device show $IFACE | sed -n '6p'` | |
mac=`cat /sys/class/net/$IFACE/address` | |
echo con = $con mac = $mac | |
activate() { | |
nmcli con add type bridge ifname br0 stp no bridge.mac $mac | |
nmcli con add type bridge-slave ifname $IFACE master br0 | |
nmcli con down "$con" | |
nmcli con up bridge-br0 | |
echo bridge activated. | |
echo if you haven\'t already, create a libvirt network that uses br0 and assign it to the VM you want to network. | |
} | |
deactivate() { | |
nmcli con del bridge-br0 | |
nmcli con del bridge-slave-$IFACE | |
# restart NM, since we can't know which con was previously attached to the iface | |
sudo systemctl restart NetworkManager | |
echo bridge deactivated. | |
} | |
$2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment