Created
August 16, 2020 14:00
-
-
Save oogali/ce67f84b6941e3bab9c7057e0e895849 to your computer and use it in GitHub Desktop.
Swap a physical interface with a bridge (KVM prep, CentOS 8)
This file contains 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/sh | |
# | |
## Interface-to-bridge swapper | |
## @oogali | |
# | |
# I want to run KVM, but I don't want dnsmasq | |
# Because I want my VMs to have direct access to the LAN broadcast domain | |
# Therefore I need a bridge interface | |
# But I don't have one already, so I must create one | |
# But I don't want to reboot nor do I want to create text files by hand | |
# So this incantation of commands will give me what I want on CentOS 8 (and probably 7 too, but untested) | |
# | |
PHYS_IF=eno1 | |
BRIDGE_IF=br-lan | |
LAN_IP=192.168.1.5/24 | |
LAN_GW=192.168.1.1 | |
virsh net-destroy default && \ | |
virsh net-autostart --network default --disable | |
cp /etc/sysconfig/network-scripts/ifcfg-${PHYS_IF} ~/ifcfg-${PHYS_IF}.bak | |
nmcli connection add type bridge ifname ${BRIDGE_IF} autoconnect yes save yes con-name ${BRIDGE_IF} bridge.stp no && \ | |
nmcli connection modify br-lan ipv4.method manual ipv4.addresses ${LAN_IP} ipv4.gateway ${LAN_GW} && \ | |
nmcli connection delete ${PHYS_IF} && \ | |
nmcli connection add type bridge-slave autoconnect yes con-name ${PHYS_IF} ifname ${PHYS_IF} master ${BRIDGE_IF} && \ | |
nmcli connection up ${BRIDGE_IF} && \ | |
nmcli connection up ${PHYS_IF} | |
diff -U1 ~/ifcfg-${PHYS_IF}.bak /etc/sysconfig/network-scripts/ifcfg-${PHYS_IF} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment