Created
April 20, 2017 21:24
-
-
Save kplimack/c99310e4db8d0512db9c46f9748d0e44 to your computer and use it in GitHub Desktop.
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/sh | |
# This is a (relatively) quick script you can use to | |
# configure bonding on production servers like splunk | |
# db's or any other prod bare metal. | |
# Usage is straight forward, invoke the script with | |
# the standard ./bondinator , and hopefully the server | |
# comes back with a clean and bonded interface. If not, | |
# to the IPMI-mobile to resurect. Backups of the | |
# network-scripts files are stored in | |
# /tmp/network-scripts_bak directory. | |
# Quick test to ensure machine isn't already bonded. | |
bond_test=$(cat /proc/net/bonding/bond0) | |
if [[ $? -eq 0 ]]; then | |
echo "This server appears to be bonded already, exiting." | |
exit 1 | |
else | |
echo "No bond detected, attempting to create" | |
fi | |
up_interfaces=($(ip addr | grep ' UP ' | awk '{print $2}' | cut -d: -f1)) | |
echo "I found the following active interfaces: ${up_interfaces[*]}" | |
ip_address=$(ip addr | grep "global ${up_interfaces[0]}" | awk '{print $2}' | cut -d/ -f1) | |
echo "Primary IP is: $ip_address" | |
echo "Backing up network-scripts folder to /var/tmp/network-scripts_bak" | |
mkdir -p /var/tmp/network-scripts_bak | |
cp /etc/sysconfig/network-scripts/* /var/tmp/network-scripts_bak | |
echo "Removing ifcfg files" | |
rm -f /etc/sysconfig/network-scripts/ifcfg-e* | |
echo "Creating new bonding scripts" | |
cat > /etc/sysconfig/network-scripts/ifcfg-bond0 <<EOF | |
DEVICE=bond0 | |
ONBOOT=yes | |
TYPE=Ethernet | |
BOOTPROTO=none | |
NM_CONTROLLED=no | |
USERCTL=no | |
BONDING_OPTS="mode=4 miimon=100" | |
IPADDR=$ip_address | |
NETMASK=255.255.240.0 | |
EOF | |
cat > /etc/sysconfig/network-scripts/ifcfg-${up_interfaces[0]} <<EOF | |
DEVICE=${up_interfaces[0]} | |
USERCTL=no | |
ONBOOT=yes | |
NM_CONTROLLED=no | |
MASTER=bond0 | |
SLAVE=yes | |
BOOTPROTO=none | |
$(grep HWADDR /var/tmp/network-scripts_bak/ifcfg-${up_interfaces[0]}) | |
EOF | |
cat > /etc/sysconfig/network-scripts/ifcfg-${up_interfaces[1]} <<EOF | |
DEVICE=${up_interfaces[1]} | |
USERCTL=no | |
ONBOOT=yes | |
NM_CONTROLLED=no | |
MASTER=bond0 | |
SLAVE=yes | |
BOOTPROTO=none | |
$(grep HWADDR /var/tmp/network-scripts_bak/ifcfg-${up_interfaces[1]}) | |
EOF | |
echo "flushing ${up_interfaces[0]}" | |
ip addr flush dev ${up_interfaces[0]} | |
echo "flushing ${up_interfaces[1]}" | |
ip addr flush dev ${up_interfaces[1]} | |
echo "restarting network service" | |
service network restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment