#!/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