Here are the steps to change the Ubuntu hostname.
To check your current hostname and summary of your machine.
hostname
hostnamectl
There a few ways to change your hostname.
sudo hostnamectl set-hostname <new hostname>
# Manually changing it in the hostname file
sudo nano /etc/hostname
# To update the prompt immediately you can issue
sudo exec bash
After changing the hostname you might want to change/add the new name to the hosts file.
sudo nano /etc/hosts
A sample of the hosts file.
![](https://dracocybersecurity.com/wp-content/uploads/2023/02/image-34-1024x175.png)