updated for centos 8

This commit is contained in:
2021-01-25 19:14:00 -05:00
parent 8c85917069
commit d5f88521eb

View File

@@ -1,37 +1,36 @@
#!/bin/bash
PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin
INTERFACES=$(ip link | grep "state UP" | awk '{ if($2 != "bond0:" && $2 != "idrac:") print substr($2,1,length($2)-1)}')
PRIMARY="enp0s31f6"
SECONDARY="enp1s0f0"
BOND="bond0"
BOND_SLAVE0="${BOND}-slave0"
BOND_SLAVE1="${BOND}-slave1"
for n in $INTERFACES; do
# Make sure both the interfaces are setup as slaves
cat > /etc/sysconfig/network-scripts/ifcfg-$n <<EOL
NAME="$n"
DEVICE="$n"
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
EOL
if [ "$n" != "eno1" ]; then
# makse sure to setup bond0 with th enp65s0 as the primary for 10gb
cat > /etc/sysconfig/network-scripts/ifcfg-bond0 <<EOL
DEVICE=bond0
NAME=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=10.0.10.11
NETMASK=255.255.255.192
GATEWAY=10.0.10.1
DNS1=10.0.10.1
ONBOOT=yes
BOOTPROTO=none
BONDING_OPTS="primary=$n mode=1 miimon=100"
EOL
fi
done
# Delete the old connections
nmcli connection delete ${BOND}
nmcli connection delete ${PRIMARY}
nmcli connection delete ${SECONDARY}
nmcli connection delete ${BOND_SLAVE0}
nmcli connection delete ${BOND_SLAVE1}
# restart the network
systemctl restart network
# Create the bond
nmcli connection add type team con-name ${BOND} ifname ${BOND} config '{"runner":{"name":"activebackup"},"ports":{"'${PRIMARY}'":{"prio":100}}}'
nmcli connection modify ${BOND} ipv4.addresses 10.0.20.28/27
nmcli connection modify ${BOND} ipv4.gateway 10.0.20.1
nmcli connection modify ${BOND} ipv4.dns 10.0.20.1
nmcli connection modify ${BOND} ipv4.method manual
nmcli connection modify ${BOND} connection.autoconnect yes
# Add the slaves to the bond
nmcli connection add type team-slave con-name ${BOND_SLAVE0} ifname ${PRIMARY} master ${BOND}
nmcli connection add type team-slave con-name ${BOND_SLAVE1} ifname ${SECONDARY} master ${BOND}
# Activate the devices
nmcli device connect ${BOND}
nmcli device connect ${PRIMARY}
nmcli device connect ${SECONDARY}
# Restart the bond0 connections
nmcli connection down ${BOND} && nmcli connection up ${BOND}