#! /bin/bash
ip=192.168.12.230 //要更改的IP地址
mask=255.255.255.0 //要更改的掩码
gateway=192.168.12.1 //要更改的网关
oldip=`cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR|awk -F "=" '{print $2}'`
oldmask=`cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep NETMASK|awk -F "=" '{print $2}'`
oldgateway=`cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep GATEWAY|awk -F "=" '{print $2}'`
sed -i 's/'$oldip'/'$ip'/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's/'$oldmask'/'$mask'/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's/'$oldgateway'/'$gateway'/g' /etc/sysconfig/network-scripts/ifcfg-eth0
service network restart
ip=192.168.12.230 //要更改的IP地址
mask=255.255.255.0 //要更改的掩码
gateway=192.168.12.1 //要更改的网关
oldip=`cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR|awk -F "=" '{print $2}'`
oldmask=`cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep NETMASK|awk -F "=" '{print $2}'`
oldgateway=`cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep GATEWAY|awk -F "=" '{print $2}'`
sed -i 's/'$oldip'/'$ip'/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's/'$oldmask'/'$mask'/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's/'$oldgateway'/'$gateway'/g' /etc/sysconfig/network-scripts/ifcfg-eth0
service network restart
转载于:https://blog.51cto.com/2213075/560139