#!/bin/bash
FILE='/root/ip'
read -p "ipaddr:" MYIP
read -p "netmask:" MYMASK
if grep -E "^BOOTPROTO=(dhcp)|(bootp)$" $file &>/dev/null ;then
sed -i "s/^BOOTPROTO=.*/BOOTPROTO=static/g" $file
grep "^IPADDR=.*" $file &>/dev/null && sed -i "s/IPADDR=.*/IPADDR=$MYIP/g" $file || sed -i "/BOOTPROTO=.*/a \IPADDR=$MYIP" $file
grep "^NETMASK=.*" $file &>/dev/null && sed -i "s/NETMASK=.*/NETMASK=$MYMASK/g" $file || sed -i "/BOOTPROTO=.*/a \NETMASK=$MYMASK" $file
fi
本文转自 张玉坡 51CTO博客,原文链接:http://blog.51cto.com/fighter/463076