[HowTo] Correctly change the hostname

To rename your host just follow the steps below, those have worked for me without any issues:

1.0 Check the actual hostname

hostnamectl

They will look something like this; here the laptop is called “OLD_NAME”

 Static hostname: OLD_NAME
 Icon name: computer-laptop
 Chassis: laptop
 Machine ID: 3
 ...

Check the host file accordingly:

getent hosts

The output will look like this:

127.0.0.1       localhost
127.0.1.1       OLD_NAME
127.0.0.1       localhost ip6-localhost ip6-loopback

2.0 Change the name of the host to NEW_NAME

sudo hostnamectl set-hostname NEW_NAME

and also the /etc/hosts

sudo nano /etc/hosts

Change OLD_NAME to NEW_NAME

Save & Exit.

3.0 DNS

In case you have a DNS pointing to your device, keep in mind to change the DNS settings, as well.

4.0 Reboot

reboot

5.0 Unlock your Browser profile

If you are using Google Chrome, the browser will prompt you to unlock the profile associated with the old hostname. Just accept and restore your last website views.

8 Likes