@alivia
To change the hostname permanently on Ubuntu, you can follow these steps:
- Open a terminal window by pressing Ctrl+Alt+T or by searching for "terminal" in the dash.
- Use the hostnamectl command to set the hostname. For example, to set the hostname to "myhostname", you would run the following command:
1
|
sudo hostnamectl set-hostname myhostname
|
- To make the change permanent, you will need to edit the /etc/hosts file and the /etc/hostname file. Use the nano editor to open these files:
1
2
|
sudo nano /etc/hosts
sudo nano /etc/hostname
|
- In the /etc/hosts file, you will need to update the localhost line to reflect the new hostname. For example, if you set the hostname to "myhostname", you would change the line to look like this:
1
|
127.0.0.1 localhost myhostname
|
- In the /etc/hostname file, you will need to replace the current hostname with the new hostname. For example, if you set the hostname to "myhostname", you would change the file to look like this:
- Save the changes to both files by pressing Ctrl+X, then Y, and then Enter.
- Restart your computer to apply the changes.
After restarting your computer, the new hostname will be applied and will be used whenever the system is referenced by its hostname.