cloud-init hostname not working as expected [RHEL8/Rocky Linux/Centos 8]


New Member
Aug 26, 2021

I've searched the other topics but there doesn't seem to be a definitive answer and as far as i saw, noone mentioned the fqdn entry.

i've configured a cloud-init ready image on rocky linux 8 (rhel8 clone)
the network, public key and user work fine. when I mount the /dev/sr0 and have a look at the cloud init files, the hostname is set aswell:

[root@judihui sr0]
$ cat user-data

hostname: SRVRLRCLB01
manage_etc_hosts: true
user: root
disable_root: False
password: VALUE HIDDEN
  - ssh-rsa VALUE HIDDEN

  expire: False
package_upgrade: true

as far as i can see, the hostname is set correctly (the name i gave the vm).
there is nothing special in the network-data and meta-data

but when i start the vm, the hostname is not really the hostname.
it just keeps whatever was set before. when I change the hostname (hostnamectl set-hostname XYZ) then it persists...

what i found was in the /var/lib/cloud/data/set-hostname

 "fqdn": "XYZ",
 "hostname": "SRVRLRCLB01"

but I have no idea where this XYZ is saved..

I tried putting the following lines in /etc/cloud/config.cfg
preserve_hostname: false
prefer_fqdn_over_hostname: false

the hostname variable is definitly set correct as it gets applied to the /etc/hosts file (this is done via the /etc/cloud/tempaltes/hosts.rhel.tmpl template)

so my question is: is there a way to find out where this fqdn entry comes from?
can we somehow change the behavior to set the fqdn instead of hostname / extend the config in the ui to change that?
I found a solution :)

if you change the vm name to something like then the fqdn gets set and the hostname is correct.
Sorry to dig this up again...
I just tested this and found the same behavior with a Centos 8.4 cloud image, Ubuntu cloud image works fine.
If I just use a hostname as the VM name, the Centos VM hostname ends up as "localhost". If I use a FQDN as the VM name, then the hostname gets set properly. Although /etc/hostname has the FQDN as opposed to just the hostname.
So would this be a bug with proxmox cloud-init or with the Centos cloud-init? And who should fix it?
Last edited:
Are you using custom user-data? If you are, then you also need custom metadata.
For example:
qm config 2000|grep ci
cicustom: user=bbnas:snippets/centos.user,meta=bbnas:snippets/centos.meta.2000

The VM is based on Centos8:
importing disk '/mnt/pve/bbnas/template/iso/CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2' to VM 2000 ...
  Logical volume "vm-2000-disk-0" created.

more /mnt/pve/bbnas/snippets/centos.meta.2000
"instance-id": "2000",
"local-hostname": "vm2000"

VM boots with hostname properly set:
[  OK  ] Started Execute cloud user/final scripts.
[  OK  ] Reached target Cloud-init target.

CentOS Linux 8
Kernel 4.18.0-305.3.1.el8.x86_64 on an x86_64

Activate the web console with: systemctl enable --now cockpit.socket

vm2000 login

When using PVE generated cloud-init, the meta-data file does not include hostname, and even though the hostname is set initially properly, it is then changed to localhost according to log:
 Updating hostname to localhost (vm2000)
. This could be artifact of a version of cloud-init that Centos is using, or default options they adopted.
I suggest opening a bugzilla to track this for a more universal cloud image support.

Blockbridge : Ultra low latency all-NVME shared storage for Proxmox -


The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!