How to change hostname on Amazon Linux 2 without reboot

https:/‮l.www/‬autturi.com
How to change hostname on Amazon Linux 2 without reboot

To change the hostname on an Amazon Linux 2 system without rebooting, you can use the hostnamectl command. hostnamectl is a utility for managing the hostname on Linux systems.

To change the hostname, follow these steps:

  1. Open a terminal window.

  2. Use the hostnamectl command to set the hostname. To do this, use the following command, replacing new_hostname with the desired hostname:

sudo hostnamectl set-hostname new_hostname

This will change the hostname to new_hostname without rebooting the system.

  1. Update the /etc/hosts file to reflect the new hostname. To do this, open the /etc/hosts file in a text editor and update the hostname in the first line. For example:
sudo nano /etc/hosts

Change the first line from:

127.0.0.1 localhost localhost.localdomain old_hostname

to:

127.0.0.1 localhost localhost.localdomain new_hostname

Save the /etc/hosts file and exit the text editor.

  1. Restart the network to apply the changes. You can do this using the following command:
sudo systemctl restart network

After the network has been restarted, the hostname will be changed to the new value.

Created Time:2017-10-16 14:38:44  Author:lautturi