🖥️ 修改主机名的方法
方法一:使用hostnamectl命令
使用hostnamectl命令 —会自动修改/etc/hostname,重新登录后生效
hostnamectl set-hostname vm63centos
方法二:直接修改配置文件
修改配置文件 /etc/hostname 保存退出
vi /etc/hostname
输入新的主机名,例如:
vm239centos
不重启好像能生效
🔄 修改hosts文件
腾讯云Centos7服务器修改/etc/hosts https://www.jianshu.com/p/2e27a4d7b9aa
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 VM_100_63_centos VM_100_63_centos
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 VM_100_63_centos VM_100_63_centos
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
修改模板文件:
vi /etc/cloud/templates/hosts.redhat.tmpl
添加:
192.168.100.63 vm63centos
修改云配置:
vi /etc/cloud/cloud.cfg
修改或删除manage_etc_hosts的值
📝 验证主机名
查看当前主机名:
hostname
查看主机名详细信息:
hostnamectl status