? ? ?linux下修改主機名比較麻煩,需要3步:
1.使用 hostname 修改當前主機名。
hostname new-hostname
2.修改 /etc/sysconfig/network? 配置文件,以便下次重啟的時,使用新的主機名。
打開 /etc/sysconfig/network 文件,修改 HOSTNAME=new-hostname.domainname。
修改后的 /etc/sysconfig/network 文件如下:
NETWORKING=yes
HOSTNAME=new-hostname.localdomain
3.修改本機的域名解析文件 /etc/hosts ,使得本機的應用程序能夠解析新的主機名。
編輯文件: /etc/hosts
修改: xxx.xxx.xxx.xxx new-hostname.domainname new-hostname
(這里的xxx代表本機的網(wǎng)絡地址,也可以是環(huán)回地址127.0.0.1)
修改后的 /etc/hosts 文件如下:
127.0.0.1? localhost.localdomain localhost
127.0.0.1? new-hostname.localdomain new-hostname