Created
May 7, 2010 15:05
-
-
Save ehabkost/393525 to your computer and use it in GitHub Desktop.
Blindly follows the instructions from http://wiki.libvirt.org/page/Networking#Fedora.2FRHEL_Bridging
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/bash | |
# make-bridge-for-libvirt.sh | |
# | |
# This scripts follows blindly the instructions from: | |
# http://wiki.libvirt.org/page/Networking#Fedora.2FRHEL_Bridging | |
# | |
# It tries to copy the existing physical network config | |
# to the bridge. It may not work if you have a non-trivial | |
# network setup on ifcfg-eth0. | |
# | |
# ---------------------------------------- | |
# | |
# Copyright (c) 2010 Eduardo Habkost <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in | |
# all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
# THE SOFTWARE. | |
# | |
must_not_exist() | |
{ | |
if [ -e "$1" ];then | |
echo "A $1 file already exists" >&2 | |
exit 1 | |
fi | |
} | |
iface="$1" | |
bridge="$2" | |
if [ -z "$iface" -o -z "$bridge" ];then | |
echo "Usage: make-bridge-for-libvirt.sh ethX brX" >&2 | |
exit 1 | |
fi | |
cd /etc/sysconfig/network-scripts/ | |
if [ ! -r "ifcfg-$iface" ];then | |
echo "No ifcfg-$iface?" >&2 | |
exit 1 | |
fi | |
orig="orig.ifcfg-$iface" | |
must_not_exist "$orig" | |
bcfg="ifcfg-$bridge" | |
must_not_exist "$bcfg" | |
echo "Disabling NetworkManager..." | |
chkconfig NetworkManager off | |
echo "Enabling network service..." | |
chkconfig network on | |
echo "Stopping NetworkManager..." | |
service NetworkManager stop | |
echo "Starting network service..." | |
service network start | |
echo "Copying eth0 network configuration to bridge..." | |
mv ifcfg-$iface $orig | |
cp $orig $bcfg | |
sed -i -e '/DEVICE=.*$/d' $bcfg | |
sed -i -e '/TYPE=.*/d' $bcfg | |
sed -i -e '/HWADDR=.*/d' $bcfg | |
echo "DEVICE=$bridge" >> $bcfg | |
echo "TYPE=Bridge" >> $bcfg | |
echo "NM_CONTROLLED=no" >> "$bcfg" | |
echo "ONBOOT=yes" >> "$bcfg" | |
echo "DELAY=0" >> "$bcfg" | |
echo "Creating eth0 configuration for br0..." | |
HWADDR= | |
source "./$orig" | |
export HWADDR | |
( | |
echo "DEVICE=$iface" | |
echo "HWADDR=$HWADDR" | |
echo "ONBOOT=yes" | |
echo "BRIDGE=$bridge" | |
echo "NM_CONTROLLED=no" | |
) > "ifcfg-$iface" | |
echo "done." | |
echo "Now, cross your fingers and run:" | |
echo " service network restart" | |
echo "Good luck!" |
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/bash | |
# A br0 bridge should be already set up. | |
# Compare with: | |
# http://en.wikibooks.org/wiki/QEMU/Networking#qemu-ifup | |
# | |
# For the bridge setup, see: | |
# http://wiki.libvirt.org/page/Networking#Fedora.2FRHEL_Bridging | |
# http://gist.github.com/393525 | |
ip link set "$1" up | |
brctl addif br0 "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment