How2 Change Linux Hostname Persistent

If you like to change the hostname persistent you have to do it in two places, otherwise, it will not persistent after reboot:

On newer Linux machines you can check the current state with:

> hostnamectl

you can find the transit and the static hostname here and it shows you also if you are on a virtual machine or a dedicated host.

to change the transit hostname:

> sudo hostname <new-name>

to change the static hostname:

> sudo hostnamectl set-hostname <hostname>

——————————————————
The above was the best solution I could found.
——————————————————

The following will may help with older machines:

To make it persistent after a reboot:

> sudo nano /etc/hostname

change here the hostname.

> sudo nano /etc/host

=================================================================
127.0.0.1 localhost hostname.hg-system.com hostname
#The following lines are desirble for IPV6 capable hosts
::1 localhost hostname.hg-system.com hostname ip6-localhost ip6-loopbac$
fe00::0 ip6-localnet
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
=================================================================
replace hostname with the new hostname

To test that the file is set up correctly, run:

> sudo service hostname start

If you get the error: Failed to start hostname.service: Unit hostname.service is masked.

systemctl unmask hostname.service
systemctl unmask hostname

Schreibe einen Kommentar