How do I change the computer name?
You need to edit the computer name in two files:
/etc/hostname
and
/etc/hosts
These will both need administrative access, so run
gksu gedit /path/to/file
Replace any instances of the existing computer name with your new one. When complete run
sudo service hostname start
The name will also be changed if you restart your computer.
See also:
- How do I change the hostname without a restart?
hostnamectl set-hostname
on 13.10+ desktop
This is the best way if you have systemd (13.10 onwards) and if cloud-init is not active (see below):
hostnamectl set-hostname 'new-hostname'
It:
- does not require rebooting
- persists after reboots
More info at: https://askubuntu.com/a/516898/52975
18.04 onwards: cloud-init
18.04 Introduced cloud-init which can control setting of the hostname so hostnamectl
changes it won't stick after a reboot if cloud-init is installed. TODO: how to check if it is installed, is it installed by default on the desktop image or just server?
If you want hostnamectl
changes to stay after a reboot, then you'll need to edit the cloud-init config files, disable cloud-init's hostname set/update module:
sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/' /etc/cloud/cloud.cfg
or disable cloud-init entirely:
sudo touch /etc/cloud/cloud-init.disabled
See also: How do I change the hostname without a restart?
It's quite easy:
Edit
/etc/hostname
, make the name change, save the file.You should also make the same changes in
/etc/hosts
fileRun
sudo service hostname start
As long as you have no application settings depending on the 'old' hostname, you should be ok ;-)