When you first create an EC2 instance, set the hostname and reboot it you may notice the hostname and shell prompt are reset to ip-xx-xx-xx-xx.ec2.internal.  In my test I used a red hat machine on the free tier.  The machine is only using a private ip, with no public ip assigned.

  1. Get your private ip
    1. curl
    2. or get if from DNS host
      1. grep nameserver /etc/resolv.conf
  2. Edit your /etc/hosts file and add a line:
    1. xx-xx-xx-xx (your ip)  your-name.us-east-1.net (your hostname)
    2. check the link above or man page for formatting
  3. Update the /etc/sysconfig/network file
    1. HOSTNAME=your-name.us-east-1..net

  4. Update the /etc/cloud/cloud.cfg
    1. add the following line – “preserve_hostname: true”
  5. reboot your machine and confirm your hostname persists
    1. run hostname [-f]