1. 查看主机名
root@Ubuntu_Lee:~# hostname
Ubuntu_Lee
2. 修改主机名
2.1 临时修改主机名
root@Ubuntu_Lee:~# hostname RadiantJeral
root@Ubuntu_Lee:~# hostname
Radiantjeral
修改hostname在shell中还未生效
重新打开shell
root@RadiantJeral:~$
2.2 永久修改主机名
在Ubuntu系统中永久修改主机名也比较简单。主机名存放在/etc/hostname
文件中,修改主机名时,编辑hostname
文件,在文件中输入新的主机名并保存该文件即可。重启系统后,参照上面介绍的快速查看主机名的办法来确认主机名有没有修改成功。
值的指出的是,在其它Linux发行版中,并非都存在
/etc/hostname
文件。如CentOS发行版将主机名存放在/etc/sysconfig/network
文件中。所以,修改主机名时应注意区分是哪种Linux发行版。
2.3/etc/hostname
与/etc/hosts
的区别
/etc/hostname
中存放的是主机名,hostname文件的一个例子:
root@Ubuntu_Lee:~# vim /etc/hostname
Ubuntu_Lee
/etc/hosts存放的是域名与ip的对应关系,域名与主机名没有任何关系,你可以为任何一个IP指定任意一个名字,hosts文件的一个例子:
127.0.0.1 localhost
127.0.1.1 radiantjeral