0

I am using Amazon Linux on EC2, passing the following cloud init directives as user data on setup:

#cloud-config
hostname: example.com
locale: en_US.utf8
manage_etc_hosts: true
manage_resolv_conf: false
package_update: true
package_upgrade: true
timezone: Europe/Berlin

Everyting works fine, except the hostname. Somehow it doesn't change, even after a reboot it's still at the IP address. If I try exactly the same with a Red Hat Enterprise Linux AMI, everything works fine - including the hostname. Does anybody know how I can get this working on Amazon Linux, too?

1 Answers1

2

I've had this exact problem, several times over. The only way I found to get around was to force it using the crontab to set it on reboot;

Type:

crontab -e -u root

Put into it:

@reboot /usr/bin/hostname web1.whatever.com

You may want to confirm the location of hostname (use which hostname and put the full path in, crontab rarely has a $PATH and can't find binaries outside of /bin for the most part). Save and exit. If you wish, reboot.

When it comes back up, hostname should be as you set it.

dannosaur
  • 983
  • 5
  • 15