I have often built a new desktop or server without giving much thought to the hostname I should use. I then become too lazy to ever change it later, leaving it set to something unhelpful or inappropriate for the purposes of deployment.
Thankfully it’s very easy to change your server hostname in Ubuntu, and across all other Linux distributions in general. It’s as simple as issuing a couple of commands via a command line interface, editing two files, and then a quick reboot to puts the changes into action. So there’s no real excuse not to right your previous wrong.
Let’s get started.
First up, let’s edit the ‘hostname’ file replacing the existing entry with our new hostname:
nano -w /etc/hostname
Next up, edit the ‘hosts’ file replacing the old hostname with the new:
nano -w /etc/hosts
You can reboot your machine immediately for the new hostname to take effect. Or alternatively, just issue the following command line to implement the hostname changes without a restart:
sudo /etc/init.d/hostname.sh start
Others may prefer to substitute “nano -w” with their preferred command line text editing tool. I’ve been using Pico/Nano since Cobalt RaQ server days, and I’ve never grown out of the habit.