更改IP的Shell脚本

生产环境中Linux服务器都采用静态IP地址,在此为大家贡献一个更改IP的Shell脚本


#!/bin/bash
#Usage:./changes_ip.sh ip netmask gateway
#By Crushlinux 2013-08-12
IP_PATH=/etc/sysconfig/network-scripts/ifcfg-eth0
GW_PATH=/etc/sysconfig/network
ip_address=$1
netmask=$2
gateway=$3
#create ip_address
echo "DEVICE=eth0" > $IP_PATH
echo "BOOTPROTO=static" >> $IP_PATH
echo "IPADDR=$ip_address" >> $IP_PATH
echo "NETMASK=$netmask" >> $IP_PATH
echo "GATEWAY=$gateway" >> $IP_PATH
echo "ONBOOT=yes" >> $IP_PATH
#create gateway
sed -i "s/^GATEWAY.*$/GATEWAY=$gateway/g" $GW_PATH
/etc/init.d/network restart



你可能感兴趣的:(更改IP的Shell脚本)