Ubuntu – changing the hostname

To change the hostname of an Ubuntu installation, you can run the following commands:
sudo hostnamectl hostname <newname>
sudo bash -c "sed -i 's/<currentname>/<newname>/g' /etc/hosts"Then reboot, to make sure there are no problems with services that were started before the change.