码迷,mamicode.com
首页 > 其他好文 > 详细

配置IP地址及HOSTNAME脚本

时间:2015-05-04 11:31:15      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash

#修改IP及HOSTNAME

 ETHCONF=/etc/sysconfig/network-scripts/ifcfg-eth0
 HOSTS=/etc/hosts
 NETWORK=/etc/sysconfig/network
 DIR=/root/backup/`date +%Y%m%d` 
 NETMASK=255.255.255.0
 
 function Change_ip () 
{ 
if [ ! -d $DIR ];then
 mkdir -p $DIR   
fi

 echo "Now Change ip address ,Doing Backup Interface eth0"
 cp $ETHCONF $DIR 
 
 read -p "Please insert ip Address:" IPADDR 
 sed -i "s/IPADDR=.*/IPADDR=$IPADDR/g" $ETHCONF 
 echo "This IP address Change success !"
 
}

function Change_hosts () 
{ 
  
if [ ! -d $DIR ];then
 mkdir -p $DIR 
fi
  
 cp $HOSTS $DIR 
 echo "Please insert IP and HOSTNAME"
 read -p "Please insert ip address": IPADDR 
 read -p "Please insert HOSTNAME": HOSTNAMES
   
if [ -n $IPADDR -a -n $HOSTNAMES ];then
 echo $IPADDR  $HOSTNAMES >> $HOSTS
 sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAMES/g" $NETWORK
 echo "This hosts change success "
else
 echo "This $host IS Exist .........."
fi

}


 PS3="Please Select ip or hosts Menu": 
 select i in "Change_ip" "Change_hosts" "Reboot" "Quit" 
  
do
case $i in
  Change_ip ) 
  Change_ip 
;; 
  Change_hosts ) 
  Change_hosts 
;; 
  Reboot )
  sync;sync;sync;init 6
;; 
  Quit )
  exit 0
;;
  *) 
  echo
  echo "Please Insert $0: Change_ip(1)|Change_hosts(2)"
  echo
;; 
esac 
done

 

参考:http://www.jb51.net/article/56611.htm

配置IP地址及HOSTNAME脚本

标签:

原文地址:http://www.cnblogs.com/storymedia/p/4475529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!