1.切换到root用户下,打开该文件,把里面的内容更改为你所需要的设定的主机名: vim /etc/hostname 2.更改hosts文件,格式如下: vim /etc/hosts 3.重启服务器后,更改生效。