#!/bin/bash IFO() { read -p "Configure $line Network card ( 'yes'or'no' )?" CDN </dev/tty if [ "${CDN}" == yes ];then ADD_D else echo "quiting" exit fi } NET_W() { while :;do STR=`cat /etc/udev/rules.d/70-persistent-net.rules | grep SUBSYSTEM= | cut -d' ' -f7 | cut -d= -f2 | sed 's/"//g'` echo "$STR" | while read line;do echo $line done echo "please input configure network card?" read name line=$name IFO continue done } IPC() { echo $1 | grep -oP '((d)+.){3}d+' &>/dev/null until [ $? -eq 0 ];do echo -e " 33[33mIP address error! Please run again... 33[0m" exit 4 done } CAT_C() { BOOT_D=`cat /etc/sysconfig/network-scripts/ifcfg-$line | grep BOOTPROTO | awk -F '=' '{print $2}'` if [ $BOOT_D == dhcp ];then echo -e "now is 33[31m$BOOT_D 33[0m Type" elif [ $BOOT_D == none ];then echo -e "now is 33[31m$BOOT_D 33[0m Type" elif [ $BOOT_D == static ];then echo -e "now is 33[31m$BOOT_D 33[0m Type" else echo "option error..." fi } ADD_D() { [ -f /etc/sysconfig/network-scripts/ifcfg-$line ] && echo -e "configure network card: 33[1;34m $line 33[0m" if [ $? -eq 1 ];then echo -e "####################### Not found $line configure file ###################################" continue fi CAT_D=`cat /etc/sysconfig/network-scripts/ifcfg-$line | grep -v "#" | egrep "IPADDR|NETMASK|GATEWAY" || echo "Parameter is null"` echo -e " 33[31m******************************* 33[0m 33[1;34m A total of $STR now ncurrent netwrok $line: $CAT_D 33[0m" CAT_C echo -e " 33[31m************************************* 33[0m" read -p "Please input IPADDR :" II </dev/tty IPC $II read -p "Please input GATEWAY :" GA </dev/tty IPC $GA read -p "Please input NETMASK :" NE </dev/tty IPC $NE III="IPADDR=$II" GAA="GATEWAY=$GA" NEE="NETMASK=$NE" PATH1="/etc/sysconfig/network-scripts/ifcfg-$line" IPADDR_D=`cat /etc/sysconfig/network-scripts/ifcfg-$line | grep "IPADDR="` NETMASK_D=`cat /etc/sysconfig/network-scripts/ifcfg-$line | grep "NETMASK="` GATEWAY_D=`cat /etc/sysconfig/network-scripts/ifcfg-$line | grep "GATEWAY="` sed -i "s/$IPADDR_D/$III/g" $PATH1 &>/dev/null || echo $III >> $PATH1 sed -i "s/$NETMASK_D/$NEE/g" $PATH1 &>/dev/null || echo $NEE >> $PATH1 sed -i "s/$GATEWAY_D/$GAA/g" $PATH1 &>/dev/null || echo $GAA >> $PATH1 sed -i 's/ONBOOT=no/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-$line sed -i 's/NM_CONTROLLED=yes/NM_CONTROLLED=no/g' /etc/sysconfig/network-scripts/ifcfg-$line sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-$line sed -i 's/BOOTPROTO=none/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-$line ifdown $line && ifup $line &>/dev/null && echo "restart network card finished" ASA=`cat /etc/sysconfig/network-scripts/ifcfg-$line` echo -e " 33[35m$ASA 33[0m" } NET_W