Change an Ubuntu Hostname

Submitted by admin on Wed, 01/06/2010 - 17:47

I recently had to change the hostname on an Ubuntu machine. There are three steps which I did not find documented together.

  • Modify the file /etc/hostname:
    1.       $ sudo vim /etc/hostname
    2.    
  • Update the hosts file /etc/hosts so that it has an updated name pointing to its own ip address:
    1.       $ sudo vim /etc/hostname
    2.    
  • If you want to do this without actually restarting the system you'll need to manually tell the machine it has a new hostname by running the hostname command(optional):
    1.       $ sudo hostname <yournewname>
    2.