阿里云服务器修改主机名

前言

每次连接服务器捣鼓东西的时候看见一长串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
  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dululuya

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值