Dyego Eugenio/Set AWS CentOS7 Hostname

Created Tue, 20 Jun 2017 17:47:09 +0300 Modified Sun, 26 Jun 2022 17:51:04 +0000

Let’s create a way to change CentOS7 hostname on AWS.

First thing, connect in your instance and…

set the hostname

hostnamectl set-hostname --static hostname.domain.tld

After, you should edit cloud.cfg

vi /etc/cloud/cloud.cfg

and add preserve_hostname: true

...
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

preserve_hostname: true

# vim:syntax=yaml

Other thing very important when you use EC2 instances is to setup the timezone.

ln -sf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime