# !/bin/bash touch /ip.txt read -p "Please put in the version(1.centos5.x-6.x 2.centos7.x 3.ubuntu or debian): " ZZ read -p "Please put in the network name: " WW echo "Please put in the ip ranges: " cat> /ip.txt CC=-1 DD=0 while read ips; do a1=`echo $ips|awk -F'/'+ '{ print $2 }'` a2=`echo $ips|awk -F'/'+ '{ print $1 }'` a3=`echo $a2 | awk -F. '{print $1"."$2"."$3}'` a4=`echo ${a2##*.}` let CC=$CC+1 let n=$a4+2 if [[ $ZZ -eq 1 ]];then cd /etc/sysconfig/network-scripts/ if [[ $a1 -eq 24 ]];then touch ./ifcfg-$WW-range$CC let y=$n+252 echo "DEVICE=$WW BOOTPROTO=static CLONENUM_START=$DD IPADDR_START=$a3.$n IPADDR_END=$a3.$y NETMASK=255.255.255.0 ONBOOT=yes">>./ifcfg-$WW-range$CC let DD=$DD+253 elif [[ $a1 -eq 26 ]];then touch ./ifcfg-$WW-range$CC let y=$n+60 echo "DEVICE=$WW BOOTPROTO=static CLONENUM_START=$DD IPADDR_START=$a3.$n IPADDR_END=$a3.$y NETMASK=255.255.255.192 ONBOOT=yes">>./ifcfg-$WW-range$CC let DD=$DD+61 elif [[ $a1 -eq 27 ]];then touch ./ifcfg-$WW-range$CC let y=$n+28 echo "DEVICE=$WW BOOTPROTO=static CLONENUM_START=$DD IPADDR_START=$a3.$n IPADDR_END=$a3.$y NETMASK=255.255.255.224 ONBOOT=yes">>./ifcfg-$WW-range$CC let DD=$DD+29 elif [[ $a1 -eq 28 ]];then touch ./ifcfg-$WW-range$CC let y=$n+12 echo "DEVICE=$WW BOOTPROTO=static CLONENUM_START=$DD IPADDR_START=$a3.$n IPADDR_END=$a3.$y NETMASK=255.255.255.240 ONBOOT=yes">>./ifcfg-$WW-range$CC let DD=$DD+13 elif [[ $a1 -eq 29 ]];then touch ./ifcfg-$WW-range$CC let y=$n+4 echo "DEVICE=$WW BOOTPROTO=static CLONENUM_START=$DD IPADDR_START=$a3.$n IPADDR_END=$a3.$y NETMASK=255.255.255.248 ONBOOT=yes">>./ifcfg-$WW-range$CC let DD=$DD+5 fi elif [[ $ZZ -eq 2 ]];then cd /etc/sysconfig/network-scripts/ if [[ $a1 -eq 24 ]];then for ((m=0;m<=252;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=24">>./ifcfg-$WW let DD=$DD+1 done elif [[ $a1 -eq 26 ]]; then for ((m=0;m<=60;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=26">>./ifcfg-$WW let DD=$DD+1 done elif [[ $a1 -eq 27 ]]; then for ((m=0;m<=28;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=27">>./ifcfg-$WW let DD=$DD+1 done elif [[ $a1 -eq 28 ]]; then for ((m=0;m<=12;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=28">>./ifcfg-$WW let DD=$DD+1 done elif [[ $a1 -eq 29 ]]; then for ((m=0;m<=4;m=m+1)) do let k=$DD let y=$n+$m echo "IPADDR$k=$a3.$y PREFIX$k=29">>./ifcfg-$WW let DD=$DD+1 done fi elif [[ $ZZ -eq 3 ]];then if [[ $a1 -eq 24 ]];then for ((m=0;m<=252;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.0 gateway $a3.$f ">>/etc/network/interfaces let DD=$DD+1 done elif [[ $a1 -eq 26 ]]; then for ((m=0;m<=60;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y/26 ">>/etc/network/interfaces let DD=$DD+1 done elif [[ $a1 -eq 27 ]]; then for ((m=0;m<=28;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.224 gateway $a3.$f ">>/etc/network/interfaces let DD=$DD+1 done elif [[ $a1 -eq 28 ]]; then for ((m=0;m<=12;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.240 gateway $a3.$f ">>/etc/network/interfaces let DD=$DD+1 done elif [[ $a1 -eq 29 ]]; then for ((m=0;m<=4;m=m+1)) do let k=$DD let y=$n+$m let f=$a4+1 echo "auto $WW:$k iface $WW:$k inet static address $a3.$y netmask 255.255.255.248 gateway $a3.$f ">>/etc/network/interfaces let DD=$DD+1 done fi fi done < /ip.txt rm -rf /ip.txt if [[ $ZZ -eq 1 ]];then echo " ********************************************* The ips have been added successfully! Please run service network restart *********************************************" elif [[ $ZZ -eq 2 ]];then echo " ********************************************* The ips have been added successfully! Please run service network restart *********************************************" elif [[ $ZZ -eq 3 ]];then echo " ********************************************* The ips have been added successfully! Please run /etc/init.d/networking restart *********************************************" fi #end