Update hostname and FQDN¶
For a full list of keys, refer to the update hostname module schema.
Default behavior¶
When preserve_hostname is not specified, cloud-init updates
/etc/hostname per-boot based on the cloud-provided local-hostname
setting. If you manually change /etc/hostname after boot, cloud-init will
no longer modify it.
This default cloud-init behavior is equivalent to this cloud-config:
1#cloud-config
2preserve_hostname: false
Note that the same cloud-config will also prevent cloud-init from updating the system hostname.
Prevent updates to /etc/hostname¶
This example will prevent cloud-init from updating the system hostname or
/etc/hostname.
1#cloud-config
2preserve_hostname: true
Set hostname¶
This example sets the hostname to external.fqdn.me instead of myhost.
1#cloud-config
2fqdn: external.fqdn.me
3hostname: myhost
4prefer_fqdn_over_hostname: true
5create_hostname_file: true
Override meta-data¶
Set the hostname to external instead of external.fqdn.me when
meta-data provides the local-hostname: external.fqdn.me.
1#cloud-config
2prefer_fqdn_over_hostname: false
Don’t create /etc/hostname file¶
On a machine without an /etc/hostname file, this config instructs
cloud-init not to create one.
In most clouds, this will result in a DHCP-configured hostname provided by the cloud.
1#cloud-config
2create_hostname_file: false