1. Update the current hostname
sudo hostname new-hostname
This command will instantly update the hostname which prevents having to reboot. It is not, however, persistent so your changes will be lost the next time you do reboot.
2. Update hostname File
Delete the current hostname and replace it with yours. This makes the new hostname persist when you reboot.
3. Update hosts File
If the new hostname isn’t added to the
hosts file the
sudo command won’t function properly.
Add the following on a new line after the
127.0.0.1 localhost line:
hosts file should look similar to the following:
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback