Score:0

can not change hostname

cn flag

I want to change the hostname of a Ubuntu 18.04 server.

I did:

hostnamectl --set-hostname newname --static
changed /etc/hostname file to newname
changed /etc/hosts file to newname
rm -f /etc/machine-id
dbus-uuidgen --ensure=/etc/machine-id
dbus-uuidgen --ensure
dpkg-reconfigure openssh-server

Finally I did a reboot. But after reboot there is still the old hostname. The file /etc/hostname has been changed to the old hostname.

How to permanently change the hostname?

jpbrain avatar
ca flag
hi. did you try "hostname newname" as root?
Thomas Aichinger avatar
cn flag
yes, of course all commands as root
user1449835 avatar
do flag
Have the same problem here, done all that and after reboot well, we were taken for a ride, because all our work wen't done the drain. Do have half an answer for you thought, the /etc/hosts file also get undone, found 23.04 is using a template located at /etc/cloud/templates/hosts.debian.tmpl. If you edit that file at least your hosts file will be configured correctly. We'll keep informing.
Score:0
cn flag

Additionally I had to change the file /etc/cloud/cloud.cfg

There is a setting preserve_hostname: false

I had to change that from false to true. After rebbot hostname had changed.

robm avatar
xk flag
Thank you! Wasted hours trying to change hostname on 22.04 due to this.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.