Ubuntu 10.04 修改主机名 hosname

关键字: Linux Ubuntu 主机名 hostname /etc/hostname /etc/hosts Unable to resolve hostname

一.需要修改两个地方
/etc/hostname
/etc/hosts

shily@hh-laptop:~$ cat /etc/hostname
hh-laptop
shily@hh-laptop:~$ cat /etc/hosts
127.0.0.1    localhost.localdomain    localhost
127.0.1.1    hh-laptop

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
shily@hh-laptop:~$

其中深色的地方需要统一, 否则会出现 Unable to resolve hostname的错误


二. 新建hostname的脚本[把下面内容保存文本中,并添加执行权限]

#!/bin/sh
host_name=`hostname`
host_name_new=
read -p "Input the new hostname[$host_name]: " host_name_new
echo "the hostname new you input is: $host_name_new"

if [ "$host_name_new" != "" ] && [ "$host_name_new" != "$host_name" ]
then
sed -i-`date '+%Y%m%d%H%M'` 's/'${host_name}'/'${host_name_new}'/g'  /etc/hostname  /etc/hosts
if [ $? -eq 0 ]
then
echo "hostname changed from [$host_name] to [$host_name_new]."
else
echo "execute error, are you root?"
fi
else
echo "hostname doesn't changed, leave [$host_name] default."

fi


From:http://hi.baidu.com/ati_crossfire/blog/item/f5b5db2de6fe01e08a1399f2.html




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值