I use a few t2.micro EC2 instances running RHEL7 for various general-purpose applications best suited to a small VPS. A personal preference of mine is to have short, descriptive hostnames on each system I regularly interact with, and by default, RHEL7 on AWS uses dynamic hostnames – the system’s hostname is defined by the private IP address of the instance:

Screen Shot 2016-04-10 at 00.01.22

I’m sure that’s useful in some applications (“at scale”), but it’s not what I prefer. Amazon has an article on how to set a static hostname, but it doesn’t seem correct – I have a hard time believing that every step is required. I put this to a test: rather than follow the steps to the letter, I tested each step independently, then in combination with multiple iterations, to see what was actually required. Here’s all that’s needed:

  1. Replace the contents of /etc/hostname with your desired hostname. No idea why Amazon tells you to use HOSTNAME=newhostname, just echo "newhostname" | sudo tee /etc/hostname
  2. Append preserve_hostname: true to /etc/cloud/cloud.cfg
  3. Reboot.

Caveat: I could be wrong, there could be good reasons to go through all of the other steps that Amazon’s doc explains. Can’t imagine why though!

Leave a Reply

Your email address will not be published.