2009-10-29

Change hostname on Ubuntu

In business it is a common pattern that you install one user workstation that becomes the template for others.

Basically after cloning such a template machine (e.g. using CloneZilla), the most important thing after starting the clone is to change the hostname - and here is how to do it:

There are two files to edit - and you should edit them in this order - just changing the hostname (in total should be 3 times occuring):

sudo vim /etc/hosts
127.0.0.1 nowthenewhostname localhost.localdomain localhost
127.0.1.1 nowthenewhostname

sudo vim /etc/hostname
nowthenewhostname

For those not familiar with vim - just press "i" to get into edit mode and when finished press "ESC" and enter ":x" followed by pressing "Enter".

And sure, you can use gedit instead of vim also.

See also more information on Cloning Ubuntu to Different Computer Hardware.

Related post: Virus scanning on Ubuntu, Stationary under Ubuntu.

3 comments:

Anonymous said...

Thanks. I knew about /etc/hostname having just stumbled upon it. I've only been changing that one and it was bugging me that in certain dialogs I was still seeing the old hostname show up. Good thing I'm not running a server or I'm sure I would have had bigger problems from that. This should really be doable in a gui in my opinion.

Martin Wildam said...

I don't know since when, but there is a tool for that named "hostname" in the meantime (or already longer without my notice). Type

man hostname

for more information.

Martin Wildam said...

As expected - even on more recent versions this is still the way to go - see also: here.