Linux Kickstart POST Script to Bond Two NICs

• Updated May 14, 2017


The following script can be placed in a Kickstart Profile POST script to bond two NICs when it is unknown what two NICs will be active.

This is typically more of an issue on physical servers rather than virtual machines.

for i in $(ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d' | grep eth)
do
STATUS=$(ethtool $i | grep 'Link detected' | awk -F: '{print $2}')

if [ $STATUS == 'yes' ]; then
    COUNTER=$((COUNTER+1))
    NIC[$COUNTER]="$i"
fi
done

cat << EOF1 >/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=$IPADDRESS
NETMASK=$NETMASK
USERCTL=no
BONDING_OPTS="mode=1 miimon=100 primary=${NIC[1]}"
EOF1

cat << EOF2 >>/etc/sysconfig/network-scripts/ifcfg-${NIC[1]}
MASTER=bond0
SLAVE=yes
EOF2

cat << EOF3 >>/etc/sysconfig/network-scripts/ifcfg-${NIC[2]}
MASTER=bond0
SLAVE=yes
EOF3

echo 'alias bond0 bonding' >> /etc/modprobe.conf

If you found this post useful and would like to help support this site - and get something for yourself - sign up for any of the services listed below through the provided links.

The following links are part of affiliate programs, and I will receive a referral payment from any of the services you sign-up for.

  • Get Faster Shipping: About to order some stuff on Amazon but want to get more value out of the money you would normally pay for shipping? Sign-up for a free, 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.
  • Start Investing Now: Looking to start investing some of your saved income? Get started by opening an account with Webull, where upon sign-up and opening a brokerage account with an initial deposit of $100 or more you will receive free stock(s). The promotions are always changing, so be sure to click the link to see the latest.

Thanks for reading and take care.