How to change the hostname of your Ubuntu server
This post is really more of a note to myself as I’m sure I’ll be doing this again. But hopefully someone else will stumble upon this and find it useful :).
I have a VPS hosted on Rackspace running Ubuntu 10.04 LTS server edition. I wanted to change the hostname as I originally named it the name of the application I was working on, but I’m now planning on using it for multiple things. I wanted the name to be more generic.
Step 1. Type in the following command.
sudo hostname newhostname
Step 2. Edit the /etc/hostname file and replace the text there with the new hostname and save it.
sudo vi /etc/hostname
Step 3. Edit the /etc/hosts file and replace the old hostname references to the new hostname, then save it.
sudo vi /etc/hosts
Step 4. Logout and log back in
It will now show user@newhostname in the command prompt, typing hostname will now show the new hostname, and pinging the new hostname will resolve to something.