1. 在Ubuntu系统中,主机名存放在/etc/hostname文件中,修改主机名时,编辑hostname文件,在文件中输入新的主机名并保存该文件。
sudo gedit /etc/hostname

2. 修改/etc/hosts文件夹下的hosts文件:
sudo gedit /etc/hosts
添加并保存hosts文件:
127.0.1.1 ubuntu

此处添加的ubuntu为主机名,应与第1步中hostname中的名字相同。
改好后重启即可。
/etc/hostname 与 /etc/hosts 的区别
hostname中存放的是主机名,我的hostname文件中只有一个主机名:ubuntu
hosts存放的是域名与ip的对应关系,域名与主机名没有任何关系,可为任何一个IP指定任意一个名字。
网友评论