How to permanently set hostname for Fedora host on Amazon EC2

In order to retain your desired hostname in a Fedora instance running on Amazon EC2 across reboots, there are two steps are required:

  1. Edit and set your proper hostname in: /etc/hostname
  2. Add the line “preserve_hostname: true” in the top configuration section of of the “cloud-init” YAML config file  /etc/cloud/cloud.cfg.

/etc/cloud/cloud.cfg will look something like this:

[root@myhostname ~]# more /etc/cloud/cloud.cfg
users:
– default

disable_root: 1
ssh_pwauth: 0

locale_configfile: /etc/sysconfig/i18n
mount_default_fields: [~, ~, ‘auto’, ‘defaults,nofail’, ‘0’, ‘2’]
resize_rootfs_tmp: /dev
ssh_deletekeys: 0
ssh_genkeytypes: ~
syslog_fix_perms: ~

preserve_hostname: true

cloud_init_modules:
– migrator
– bootcmd
– write-files
– growpart
– resizefs
– set_hostname
– update_hostname
– update_etc_hosts
– rsyslog
– users-groups
– ssh

…<snip>

No comments yet.

Leave a Reply