#!/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 interface[eth0 eth1]:" eth

echo "DEVICE=bond0
TYPE=bond
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
BONDING_MASTER=yes
BONDING_OPTS=\"mode=4 miimon=100 xmit_hash_policy=layer3+4\"" > /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 "DEVICE=bond0.192
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.189.
NETMASK=255.255.255.0
VLAN=yes" > /etc/sysconfig/network-scripts/ifcfg-bond0.192

echo "DEVICE=bond0.163
BOOTPROTO=static
ONBOOT=yes
VLAN=yes
IPADDR=36.151.250.66
NETMASK=255.255.255.192
GATEWAY=36.151.250.65
DEFROUTE=yes
DNS1=114.114.114.114
DNS1=119.29.29.29
DNS3=240c::6666
DNS4=240C::6644
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
IPV6ADDR=2409:8c20:28c1:503:8000::2/65
IPV6_DEFAULTGW=2409:8c20:28c1:503:8000::1" > /etc/sysconfig/network-scripts/ifcfg-bond0.163

echo "sshd:116.132.218.57 allow" >> /etc/hosts.allow
echo "sshd:106.8.131.208 allow" >> /etc/hosts.allow
echo "sshd:111.63.205.96 allow" >> /etc/hosts.allow
echo "sshd:14.119.87.209 allow" >> /etc/hosts.allow


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

