Reboot not required
hostnamectl set-hostname new-hostnameReboot required
sudo vi /etc/hostname
 
# change the stringsudo vi /etc/hosts
 
# Example content:
# 127.0.0.1 localhost
# 127.0.1.1 ubuntu-machine <- change this stringThen, reboot
Temporarily (the other approaches changes the hostname permanently)
sudo hostname new-hostname