前言
每次连接服务器捣鼓东西的时候看见一长串iZ*********************dZ的默认主机名就特别难受,非常难受,极其难受,终于受不了了把阿里云服务器默认的主机名修改掉了。
步骤
1.查看主机名
可以先切换到root用户下,使用hostname命令查看当前主机名,*号是为了给我的主机名打个码
[root@iZ*********************dZ ~]# hostname
iZ*********************dZ
2.设置新的主机名
输入命令
hostnamectl set-hostname 主机名
例如,我把我的主机名修改为dululuya,然后输入reboot命令重启
[root@iZ*********************dZ ~]# hostnamectl set-hostname dululuya
[root@iZ*********************dZ ~]# reboot
重启之后
[root@dululuya ~]# hostname
dululuya
3.重启系统后失效
参考阿里云问题解决方法
Linux系统的ECS实例修改主机名重启系统之后失效
编辑/etc/cloud/cloud.cfg文件,将preserve_hostname配置项的值由false修改为true,保存并退出
[root@dululuya ~]# vi /etc/cloud/cloud.cfg
# The top level settings are used as module
# and system configuration.
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
- default
user:
name: root
lock_passwd: False
# If this is set, 'root' will not be able to ssh in and they
# will get a message to login instead as the above $user
disable_root: false
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true //这里在这里,把这里的false改为true
manage_etc_hosts: localhost
syslog_fix_perms: root:root
datasource_list: [ AliYun ]
# Example datasource config
datasource:
AliYun:
support_xen: false
timeout: 5
max_wait: 300
"/etc/cloud/cloud.cfg" 93L, 1997C