How do I assign a static hostname to an Amazon EC2 instance running SLES?
"I changed the hostname of my Amazon Elastic Compute Cloud (Amazon EC2) instance. However, when I reboot or stop and then start the instance, the hostname changes back. How do I make the hostname persist?"
"I changed the hostname of my Amazon Elastic Compute Cloud (Amazon EC2) instance. However, when I reboot or stop and then start the instance, the hostname changes back. How do I make the hostname persist?Short descriptionTo make a hostname persist when rebooting or stopping and starting your EC2 instance, add the hostname to the appropriate configuration files on the instance.Note: The following steps apply to SLES. For instructions that apply to other distributions, see one of the following:Changing the system hostnameHow do I assign a static hostname to an Amazon EC2 instance running RHEL 5 or 6, CentOS 5 or 6, or Amazon Linux?How do I assign a static hostname to an Amazon EC2 instance running Ubuntu Linux?How do I assign a static hostname to an Amazon EC2 instance running RHEL 7 or CentOS 7?Resolution1.    Connect to your EC2 Linux instance using SSH. For more information, see Connecting to your Linux instance using SSH.2.    Switch to the root user.sudo su3.    Use the hostnamectl command to set the new hostname. Replace new-hostname with your hostname.SLES 11:hostname new-hostnameSLES 12 and SLES 15:hostnamectl set-hostname new-hostname4.    Use the vim editor to update the /etc/hosts file with the new hostname.vim /etc/hosts5.    Find the localhost string and append the new hostname. Again, replace new-hostname with your hostname.127.0.0.1 localhost new-hostname6.    Save and exit the vim editor by pressing Shift + : (colon) to open a new command entry box in the vim editor. Type wq and then press Enter to save changes and exit the vim editor.SLES 11 (additional step for this OS version only)Use the vim editor to update the /etc/HOSTNAME file with the new hostname.vim /etc/HOSTNAMEFind the current hostname string and replace it with the new hostname.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.7.    Use the vim editor to update the /etc/cloud/cloud.cfg file on your SLES Linux instance.vim /etc/cloud/cloud.cfg8.    Find the preserve_hostname string and change the default setting to true so that the hostname is preserved between restarts or reboots.preserve_hostname: true9.    Save and exit the vim editor by pressing Shift + : (colon) to open a new command entry box in the vim editor. Type wq and then press Enter to save changes and exit the vim editor.10.    Reboot the instance.sudo reboot11.    Connect to your EC2 instance, and then run the Linux hostname command without any parameters to verify that the hostname change persisted.hostnameThe command returns the new hostname.Related informationChanging the hostname of your Linux instanceFollow"