Permanently Set HOSTNAME in an AWS EC2 instance

This is more when you want to create an AMI from an EC2 image and you want it to have a persistent hostname. This was needed in our AWS based Jenkins process and was for our Centos/RHEL images, the Ubuntu/Debian process is very similar apart from stage 3 as this file does not exist:

1) Replace the “/etc/cloud/cloud.cfg” with:

hostname: [yourhostname]
fqdn: [your fully qualified domain name]
manage_etc_hosts: true
# vim:syntax=yaml

3) Edit “/etc/sysconfig/network”:

HOSTNAME=[your hostname]

4) Edit “/etc/hosts”:   [your fully qualified domain name] [yourhostname] localhost.localdomain localhost localhost4.localdomain4 localhost4

5) Stop the Instance

6) Edit the Instance’s User Data:

hostname: [yourhostname]

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.