#提取IP地址和网关
IP=`ip addr |awk '/inet /' |sed -n '2p' |awk -F' ' '{print $2}' |awk -F'/' '{print $1}'`
#MASK=`ifconfig |grep 'inet '|grep -v '127.0.0.1'|awk '{print $4}'`
GATEWAY=`route -n |sed -n '3p'|awk '{print $2}'`
INNETO=`ip addr | awk -F '^2:' '{print $2}' |awk -F ':' '{print $1}' | awk NF|awk '{sub("^ *","");sub(" *$","");print}' |sed -n 1p`
INNETW=`ip addr | awk -F '^3:' '{print $2}' |awk -F ':' '{print $1}' | awk NF|awk '{sub("^ *","");sub(" *$","");print}' |sed -n 1p`
local eth_conf=/etc/sysconfig/network/ifcfg-${INNETO}
if grep "dhcp" ${eth_conf} &>/dev/null;then
[ ! -f ${eth_conf}.bak ] && cp ${eth_conf}{,.bak}
cat > ${eth_conf} << EOF
BOOTPROTO='static'
IPADDR=${IP}
NETMASK=255.255.255.0
STARTMODE='auto'
EOF
[ ! -f /etc/sysconfig/network/routes.bak ] && cp /etc/sysconfig/network/routes{,.bak}
echo "default ${GATEWAY}" > /etc/sysconfig/network/routes
else
echo "already config static IP"
fi