#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
cp /etc/sysconfig/network-scripts/ifcfg-ens2f0 /root/
cp /etc/sysconfig/network-scripts/ifcfg-ens2f1 /root/
#create ens2f0 and ens2f1
cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-ens2f0
MASTER=bond0
SLAVE=yes
EOF
sed -i "s/BOOTPROTO=dhcp/BOOTPROTO=none/" /etc/sysconfig/network-scripts/ifcfg-ens2f0
cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-ens2f1
MASTER=bond0
SLAVE=yes
EOF
sed -i "s/BOOTPROTO=dhcp/BOOTPROTO=none/" /etc/sysconfig/network-scripts/ifcfg-ens2f1
sed -i "s/ONBOOT=no/ONBOOT=yes/" /etc/sysconfig/network-scripts/ifcfg-ens2f1
#create bond4
IP_PATH=/etc/sysconfig/network-scripts/ifcfg-bond0
read -p "Please input IP(FORMAT:192.168.1.2):" ip
#change ip address
echo "DEVICE=bond0">$IP_PATH
echo "TYPE=bond">>$IP_PATH
echo "BOOTPROTO=static">>$IP_PATH
echo "IPADDR=$ip">>$IP_PATH
echo "NETMASK=255.255.255.0">>$IP_PATH
echo "GATEWAY=10.123.1.254">>$IP_PATH
echo "ONBOOT=yes">>$IP_PATH
echo 'BONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=layer3+4"'>>$IP_PATH
echo "BONDING_MASTER=yes" >>$IP_PATH
systemctl restart network
echo "Change successful"
#umount /mnt/