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