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:
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:
- Replace the contents of
/etc/hostname
with your desired hostname. No idea why Amazon tells you to useHOSTNAME=newhostname
, justecho "newhostname" | sudo tee /etc/hostname
- Append
preserve_hostname: true
to/etc/cloud/cloud.cfg
- 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!