1. 程式人生 > >Ubuntu下檢視和修改hostname

Ubuntu下檢視和修改hostname


1. 檢視主機名

[email protected]_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