Created
April 7, 2017 11:48
-
-
Save josecolella/aafc9bc4b9a27cbfcf7b28dbe48e2477 to your computer and use it in GitHub Desktop.
RHEL 6.x and 7.x network bonding
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
makebond() { | |
BOND=$1 | |
SLAVE1=$2 | |
SLAVE2=$3 | |
IPADDRESS=$4 | |
NETMASK=$5 | |
GATEWAY=$6 | |
_HOSTNAME=$(hostname) | |
if [ "$#" -eq "7" ] | |
then | |
_HOSTNAME=$7 | |
fi; | |
if [ "$#" -gt "5" ] | |
then | |
cat << EOF1 >/etc/sysconfig/network-scripts/ifcfg-${BOND} | |
#generated by bonding script | |
DEVICE=${BOND} | |
BOOTPROTO=none | |
ONBOOT=yes | |
IPADDR=$IPADDRESS | |
NETMASK=$NETMASK | |
USERCTL=no | |
NM_CONTROLLED=no | |
BONDING_OPTS="mode=1 miimon=100 primary=${SLAVE1}" | |
#come back to primary when link comes again | |
EOF1 | |
mv /etc/sysconfig/network-scripts/ifcfg-${SLAVE1} /etc/sysconfig/network-scripts/old$$_ifcfg-${SLAVE1} | |
cat << EOF2 >>/etc/sysconfig/network-scripts/ifcfg-${SLAVE1} | |
#generated by bonding script | |
DEVICE=${SLAVE1} | |
MASTER=${BOND} | |
SLAVE=yes | |
USERCTL=no | |
ONBOOT=yes | |
NM_CONTROLLED=no | |
EOF2 | |
mv /etc/sysconfig/network-scripts/ifcfg-${SLAVE2} /etc/sysconfig/network-scripts/old$$_ifcfg-${SLAVE2} | |
cat << EOF3 >>/etc/sysconfig/network-scripts/ifcfg-${SLAVE2} | |
#generated by bonding script | |
DEVICE=${SLAVE2} | |
MASTER=${BOND} | |
SLAVE=yes | |
USERCTL=no | |
ONBOOT=yes | |
NM_CONTROLLED=no | |
EOF3 | |
mv /etc/sysconfig/network /etc/sysconfig/old$$_network | |
cat << EOF4 >/etc/sysconfig/network | |
#generated by bonding script | |
NETWORKING=yes | |
NETWORKING_IPV6=no | |
IPV6_AUTOCONF=no | |
IPV6INIT=no | |
HOSTNAME=${_HOSTNAME} | |
GATEWAY=${GATEWAY} | |
GATEWAYDEV=${BOND} | |
EOF4 | |
echo "alias ${BOND} bonding" > /etc/modprobe.d/bonding.conf | |
modprobe bonding | |
service network restart | |
else | |
echo "Usage: makebond bond0 eth0 eth1 ip netmask gateway [hostname]" | |
fi | |
} | |
###### makebond bond0 eth0 eth1 xxx.XXx.XXX.XXX 255.255.255.0 xxx.xxx.xxx.1 hostname.with.optional.fqdn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment