Update the hostname using the hostnamectl
command:
sudo hostnamectl set-hostname NEW_HOSTNAME
Edit the file manually:
sudo nano /etc/hostname
Replace the existing hostname with NEW_HOSTNAME
, then save (CTRL + X
, then Y
, then ENTER
).
Edit the /etc/hosts
file:
sudo nano /etc/hosts
Replace any instances of the old hostname with NEW_HOSTNAME
. Ensure the file contains:
127.0.0.1 localhost
127.0.1.1 NEW_HOSTNAME
Save and exit.
After completing these steps, the system will use the new hostname upon reboot.