How to Set or Change Hostname in Amazon Linux EC2 Instance

o set or change the hostname on an Amazon Linux EC2 instance, you can use the hostnamectl command. Here are the steps to set the hostname:

  1. Connect to your EC2 instance via SSH.
  2. Use the following command to set the hostname:
sudo hostnamectl set-hostname new-hostname

Replace new-hostname with the desired hostname.

  1. Verify the hostname has been changed by using the following command:
hostnamectl
  1. Edit the file /etc/hosts and change the hostname to the new hostname.
  2. Restart the instance for the changes to take effect.
sudo reboot

Please note that these steps are for Amazon Linux EC2 instances. The process may be different for other Linux distributions or cloud providers.

Leave a Comment