#!/bin/env bash

# Set environment
TIME=$(date +%Y%m%d%H%M%S)
source /etc/profile
source /etc/init.d/functions
export LANG=C
export PATH=/bin/:/sbin:/usr/bin/:/usr/sbin:/usr/local/sbin/:/usr/local/bin/:$PATH

modprobe bonding miimon=100 mode=0
echo "alias bond0 bonding
options bond0 miimon=100 mode=0" > /etc/modprobe.d/bond.conf
#systemctl stop NetworkManager.service &>/dev/null
#systemctl disable NetworkManager.service &>/dev/null
modprobe --first-time bonding  &>/dev/null

read -p "Pls input bond0 ip:" bondip
read -p "Pls input bond0 netmask:" bondnetmask
read -p "Pls input bond0 gateway:" bondgateway
read -p "Pls input bond0 interface[eth0 eth1]:" eth

echo "DEVICE=bond0
TYPE=bond
IPADDR=${bondip}
NETMASK=${bondnetmask}
GATEWAY=${bondgateway}
DNS1=223.5.5.5
DNS2=223.6.6.6
DNS3=114.114.114.114
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
BONDING_MASTER=yes
BONDING_OPTS="mode=0 miimon=100"" > /etc/sysconfig/network-scripts/ifcfg-bond0

for i in ${eth};do
echo "DEVICE=${i}
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none" > /etc/sysconfig/network-scripts/ifcfg-${i}
done

echo "service network restart..."
#systemctl restart  network
systemctl start NetworkManager.service &>/dev/null
systemctl enable NetworkManager.service &>/dev/null
