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. Use the YaST interface to update your SuSe Linux instance with the new hostname. Start by switching to the root user with the following command:
         sudo su
  2. Run the yast command.
    This launches the keyboard-interactive ASCII-based interface for YaST. Use the TAB and arrow keys to navigate YaST.
  3. In YaST, navigate to Network Devices, then Network Settings, and then press the Enter key.
  4. In Network Settings, use the arrow keys to navigate to Hostname/DNS and use the TAB key and Shift + TAB key combination to cycle through the available options.
    a. Select and set the hostname and domain name to preferred values.
    b. Navigate to Change Hostname via DHCP and press the Spacebar to uncheck this option.
    c. Use the TAB key to navigate to [ OK ] and press the Enter key to accept changes.
    d. Use the TAB key to navigate to [Quit] and press the Enter key to exit YaST.
  5. Update the /etc/cloud/cloud.cfg file on your SuSe Linux instance.
         vim /etc/cloud/cloud.cfg
    Find the following string and change its default setting to true to ensure that the hostname is preserved between restarts/reboots.
         preserve_hostname: true
    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.
  6. Run the following command to reboot the instance:
         sudo reboot
  7. After you reboot the EC2 instance, run the Linux hostname command 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, SuSe, cloud.cfg

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.