Linux Ubuntu16.04和18.04修改主机名的方法

常用命令

查看当前主机名

hostname
# 或者
uname -a

Ubuntu 16.04 修改主机名

第一步

修改/etc/hostname文件

vi /etc/hostname

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

第二步

修改/etc/hosts配置文件

vi /etc/hosts
# 在第二行添加
127.0.1.1 sunpma(sunpma为你刚才设置的主机名)

第三步

重启系统使其生效

sudo reboot

Ubuntu 18.04 修改主机名

第一步

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

vi /etc/cloud/cloud.cfg

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

第二步

修改/etc/hostname文件

vi /etc/hostname

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

第三步

修改/etc/hosts配置文件

# 在第二行添加
127.0.1.1 sunpma(sunpma为你刚才设置的主机名)

第四步

重启系统使其生效

sudo reboot

发表评论