Occasionally during development activities, or even normal server operation, you’ll want to change the hostname of Ubuntu. Here’s how:
In Ubuntu Desktop click the cog icon in the top right corner, then select About This Computer
Click in the Device name field and type a new name for your machine
Close the window to save the changes
Open a new terminal window. The new hostname will be reflected in the window title and the prompt.
In the terminal verify that the
/etc/hostnamefile has been updated
This command should output the new hostname, for example
Lastly, check the file
/etc/hostsand change the below line, where
oldhostnameis your old hostname.
If you suddenly start getting a console error like
sudo: unable to resolve host newmachinename then make sure both
/etc/hosts reflect your new hostname.