The Schworak Site | Log In | Up One Level

Changing the computer name / hostname in Ubuntu, Debian and variants

Normally, you only need to set the hostname when you first install Linux. But perhaps a poor name was chosen or an error was made during the install and you need to change it. Well a couple simple file edits will do the trick.

If you are using a GUI (or graphical user interface / desktop view) you will need to get to the command line by opening a terminal. The quick way is to press CTRL+ALT+T and a shell window should open.

Once at the command line you will need to edit two files. You can use gedit for if you are running Gnome or your favorite text based editor. I like to use vi simply because I am farmilure with the hot keys.

#> sudo vi /etc/hostname

When the file opens, simply change the host name. It should be the only text in this file. Save and exit.

#> sudo vi /etc/hosts

In this file you may see many entries. Find the one that matches the old hostname and replace it. Often you will see it as something like this: computer1

The numbers are clearly an IP address then the fully qualified domain name and lastly the alias. You may not always have both versions of the computer name. The alias (last) is not required. Again save and exit.

Finally, you have three choices for getting the system to pick-up the changes.

  1. Reboot the computer (not my favorite)
  2. sudo hostname {new_name}
  3. sudo start hostname (my favorite)

Using option #2 is fine but you have to retype the new name again and that always means you can make a mistake and you aren't going to be sure of what you will get after a reboot. Option #3 executes the script that runs at startup and gives you the exact same results as a reboot but without forcing all your other running processes to shut down. Now if you have processes that need to know about this change well maybe a reboot is in order.


Making checkboxes pass data even when they are unchecked >>
All content on this site is copyright ©2004-2024 and is not to be reproduced without prior permission.