写一个脚本:
1.提示用户选择所要设置的网卡;
2.提示用户使用dhcp或者static'作为选定网卡的BOTOPROTO
    a.如果用户选择dhcp,则将其配置文件中的BOOTPROTO的值设为dhcp,而后重启网卡;
    b.如果用户选择static,则将其配置文件中的BOOTPROTO的值设static,并提示用户输入IP地址,子网掩码和网关;其中网关可以为空,但IP地址或子网掩码不能为空;设置完成后重启次网卡;
3.无论上述动态或静态设定,设定完成后将网卡IP地址设定后信息再次显示给用户                   
 

#!/bin/bash
NPATH="/etc/sysconfig/network-scripts/"
echo "Please select the network card:"
read -p "`ls $NPATH|grep ifcfg|cut -d- -f2`:" A
read -p "Please select the BOOTPROTO between dhcp and static:" B
if [ $B = "dhcp" ];then
   sed -i 's/\(BOOTPROTO=\).*/\1dhcp/g' $NPATH"ifcfg-"$A
   service network restart
elif [ $B = "static" ];then
   sed -i 's/\(BOOTPROTO=\).*/\1static/g' $NPATH"ifcfg-"$A
   read -p "Please input IP:" IP
   [ ! -n "$IP" ]&&echo "input error!!!"&&exit 5
   sed -i 's/\(IPADDR=\).*/\1'''$IP'''/g' $NPATH"ifcfg-"$A
   read -p "Please input netmask:" MK
   [ ! -n "$MK" ]&&echo "input error!!!"&&exit 5
   sed -i 's/\(NETMASK=\).*/\1'''$MK'''/g' $NPATH"ifcfg-"$A
   read -p "Please input gateway:" GW
   sed -i 's/\(GATEWAY=\).*/\1'''$GW'''/g' $NPATH"ifcfg-"$A
   service network restart
fi
cat $NPATH"ifcfg-"$A