此脚本修改Linux下/etc/sysconfig/network-scripts/ifcfg-ethX网卡文件中的网卡一、网卡二的IP地址(IPADDR)、子网掩码(NETMASK)信息
#!/bin/sh
PROC=/bin/sed
FILE_PATH1=/etc/sysconfig/network-scripts/ifcfg-eth0
FILE_PATH2=/etc/sysconfig/network-scripts/ifcfg-eth1
IP_PRIMAL1=`grep -i ipaddr $FILE_PATH1|awk -F "=" ‘{printf $2 }‘`
MASK_PRIMAL1=`grep -i netmask $FILE_PATH1|awk -F "=" ‘{printf $2}‘`
IP_PRIMAL2=`grep -i ipaddr $FILE_PATH2|awk -F "=" ‘{printf $2 }‘`
MASK_PRIMAL2=`grep -i netmask $FILE_PATH2|awk -F "=" ‘{printf $2}‘`
IP_MODI1=192.168.1.200
MASK_MODI1=255.255.255.0
IP_MODI2=192.168.2.200
MASK_MODI2=255.255.255.0
$PROC -e "s/$IP_PRIMAL1/$IP_MODI1/g" -e "s/$MASK_PRIMAL1/$MASK_MODI1/g" $FILE_PATH1>ifcfg-eth0.bak
$PROC -e "s/$IP_PRIMAL2/$IP_MODI2/g" -e "s/$MASK_PRIMAL2/$MASK_MODI2/g" $FILE_PATH2>ifcfg-eth1.bak
cp -pf ./ifcfg-eth0.bak $FILE_PATH1
cp -pf ./ifcfg-eth1.bak $FILE_PATH2
cat $FILE_PATH1
cat $FILE_PATH2
service network restart
本文出自 “tangjiLinux” 博客,请务必保留此出处http://1132818999.blog.51cto.com/10422963/1672308
自动修改Linux下/etc/sysconfig/network-scripts/ifcfg-ethX网卡文件的脚本
原文地址:http://1132818999.blog.51cto.com/10422963/1672308