1. 程式人生 > >auto change ip and hostname

auto change ip and hostname

auto change ip and hostname

#!/bin/sh

ETHCONF=/etc/sysconfig/network-scripts/ifcfg-eth0

HOSTS=/etc/hosts

NETWORK=/etc/sysconfig/network

NETMASK=255.255.255.0

###

function Change_ip ()

{

grep "dhcp" $ETHCONF

if [ $? -eq 0 ];then

read -p "Please insert ip Address:" IPADDR

sed -i ‘s/dhcp/static/g‘ $ETHCONF

echo -e "IPADDR=$IPADDR\nNETMASK=$NETMASK\nGATEWAY=`echo $IPADDR|awk -F. ‘{print $1"."$2"."$3}‘`.2" >>$ETHCONF

echo "This IP address Change success !"

auto change ip and hostname