Amazon EC2 instance hostnames are derived from the IP address that is dynamically assigned to the instance at startup. Although you can change the hostname of a private instance of EC2 Linux by using the hostname command, if you reboot or stop/start the instance it will revert to using a hostname derived from the IP address assigned to the instance.

The Linux hostname command can be used by administrators to change the hostname of an EC2 Linux instance. If you want the new hostname to persist between instance stops/starts and reboots, you must add the new hostname to the appropriate configuration files on your EC2 Linux instance.

Update the /etc/hosts file on your Ubuntu Linux instance with the new hostname, and add IPv6 configuration data if your instance is using IPv6. sudo vim /etc/hosts Change the name associated with the IP address 127.0.0.1 to the hostname that you want the instance to use even after a restart or reboot. Typically this involves changing localhost to the new hostname. 127.0.0.1 persistent_host_name Add the following configuration information to the hosts file if the instance uses IPv6. ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts Save and exit the vim editor.Note After making this change, press SHIFT + : [colon] to open a new command entry box in the vim editor. Type wq, and then press Enter to save changes and exit vim.

Update the /etc/hostname file on your Ubuntu Linux instance with the new hostname. sudo vim /etc/hostname Save and exit the vim editor.

If you have not already done so, run the Linux hostname command and specify the new hostname if you want to begin using the new hostname without restarting. sudo hostname persistent_host_name

The next time that you restart or reboot the EC2 instance, run the Linux hostname command again without any parameters to verify that the hostname change persisted. hostname The command should return the new hostname.persistent_host_name