As we know we setup a hostname for ubuntu during installation.If need to change your hostname for some reasons or just want to change it.It’s very easy,just follow below steps,here we go.
1Press Ctl+Alt+t to open a terminal (Or search “terminal” in Dash)
2.Run below command in your terminal,type your password if prompted
sudo gedit /etc/hostname
3.Change your old hostname to your new hostname , then click Save
4.Then use below commands to change your old hostname in /etc/hosts to your new hostname
sudo gedit /etc/hosts
5.Then after next reboot ,you will have a new hostname. You also can run below command to let your new hostname take effect right now.
sudo hostname newhostname