更改主机名脚本

#!/bin/bash

#获取ip
ipaddr=`/sbin/ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d : -f2 | awk '{print $1}'`

#rename network
name=$1
hostname $name
cp /etc/sysconfig/network /etc/sysconfig/network.bak
sed -i 's/HOSTNAME=*/#HOSTNAME=*/g' /etc/sysconfig/network
echo "HOSTNAME=$name" >> /etc/sysconfig/network
echo "NETWORKING=yes" >> /etc/sysconfig/network

#add hosts
cp /etc/hosts /etc/hosts.bak
echo "$ipaddr $name" >> /etc/hosts

posted @ 2015-10-10 16:52  paul_hch  阅读(480)  评论(0编辑  收藏  举报