Ubuntu修改主机名的方法

常用命令

查看当前主机名

hostname

# 或者

uname -a

Ubuntu 16.04 修改主机名

1.修改/etc/hostname文件

vi /etc/hostname

修改成你需要的主机名后保存退出;

2.修改/etc/hosts配置文件

vi /etc/hosts

# 在第二行添加

127.0.1.1 sunpma(sunpma为你刚才设置的主机名)

3.重启系统使其生效

sudo reboot

Ubuntu 18.04 修改主机名

1.修改/etc/cloud/cloud.cfg文件

vi /etc/cloud/cloud.cfg

找到preserve_hostname: false将其修改为preserve_hostname: true

2.修改/etc/hostname文件

vi /etc/hostname

修改成你需要的主机名后保存退出;

3.修改/etc/hosts配置文件

# 在第二行添加

127.0.1.1 sunpma(sunpma为你刚才设置的主机名)

4.重启系统使其生效

sudo reboot

赞助作者:

支付宝打赏!                     微信打赏

原创声明: BD6MM 原创文章,转载必须以链接形式标明出处。

本文链接: https://bd6mm.cn/blog/2019/05/how-ubuntu-modifies-the-host-name.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注