更改ubuntu12.04和12.10的主机名

时间:2019-08-20 17:58:12  来源:igfitidea点击:

如何在不重启系统的情况下更改ubuntu12.04和12.10的主机名

编辑/etc/hosts文件

root@mymachine:~$sudo vi /etc/hosts
127.0.0.1	localhost
127.0.1.1	theitroad

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
191.168.122.26
root@mymachine:~$

编辑/etc/hostname

root@mymachine:~$sudo  vi /etc/hostname
theitroad
root@mymachine:~$

使用hostname脚本重启服务

/etc/init.d/hostname.sh restart

或者(在Ubuntu 12.10中使用)

/etc/init.d/hostname restart

退出当前终端,重新登录

检查主机名

使用hostname命令进行检查。