Change Hostname in Ubuntu
- Open Terminal.
- Run following command and make note of the current hostname:
hostname
- Run following command to edit the hostname:
sudo nano /etc/hosts
- Replace the current hostname, shown as bracketed, with your desired hostname:
127.0.0.1 localhost 127.0.1.1 [New Hostname]
- Run following command and replace the hostname to a new one:
sudo nano /etc/hostname
- Run the following to reboot and check if the changes survived.
I believe this is one of the occasions why I simply cannot recommend Ubuntu for the sake of accessibility. Any GUI-familiar users would expect the system settings to have some ways to handle hostname; both Windows and Mac have some form of it. And mosts users would expect the changes to be made system wide when a dedicated command is run. If an operating system is designed with GUI in mind, the bare minimum of that interface is to be streamlined enough so that the users do not have to jump back to CLI to make simple changes.
updated Jul 20, 2018: edited for better readability.