This is a short and sweet howto that is nonetheless very important. It is based on my experiences when changing the hostname of a system. The hostname is effectively just the name of the system. You do not usually need to change it, but if you do have to for whatever reason, it isn't very difficult at all.
Whilst changing the hostname is not a difficult task in itself, it can be dangerous because if the system cannot resolve it's own hostname, it is impossible to sudo. Thus, if done improperly, changing a hostname can lock you out of your own system. Firstly, and most importantly, we make backups. Go to accessories/terminal and paste this command in, then press enter:
You MUST make backups, just in case. If you can't boot to a usable system after finishing this howto, or sudo doesn't work, see the instructions at the end of this guide. If you aren't completely familiar with the linux terminal, it might be a good idea to write these down or print them off.
sudo cp /etc/hosts /etc/hosts.bak && sudo cp /etc/hostname /etc/hostname.bak
Ok, now we have made backups, we can edit /etc/hosts:
You should see what you are looking for fairly quickly, at the top of the file it should look something like:
sudo nano /etc/hosts
Change old_hostname to a new hostname of your choice. Now save and exit.
Second file to edit is /etc/hostname. This does what it says on the tin, the file will have one line in it and that line is your hostname. Change it to your new hostname, save and exit.
Now reboot, you should have a perfectly working system in which sudo works. You can test both sudo and your new hostname by doing, simply:
NOTE: This command does not usually need to be run sudo, we are just testing both the changed hostname AND sudo at the same time.
If it doesn't work, see below. You DID take backups, didn't you?
- Get into the grub menu by pressing esc on bootup, or allowing it to display automatically if you have set it up like this
- Choose recovery mode
- If prompted, select "drop to single user mode" or similar (note: this applies only on hardy I think)
- When you are at a root shell, type the following command:
cp /etc/hosts.bak /etc/hosts && cp /etc/hostname.bak /etc/hostname
- Then press ctrl-alt-del and you should reboot back to a perfectly working system.
That's it! If anybody has problems, post here and I'll try to help.