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.

  1. 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 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.    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.
    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.
  2. Update the /etc/hostname file on your Ubuntu Linux instance with the new hostname.
         sudo vim /etc/hostname
    Save and exit the vim editor.
  3. 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
  4. 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.
    The command should return the new hostname.

Amazon EC2, Linux, hostname, persistent, hosts,, vim, private, Ubuntu

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.