OCI Compute Instance Hostname keeps changing after reboot

I created an OCI compute Linux Instance with hostname = hostname_1.

After a while, and based on the client request, I changed the above virtual machine hostname to be hostname_2.

Client used this machine for a while, and then reboot it for some reason, but surprisingly, he found that the compute Instance hostname changed back to the original one, which is hostname_1!!!

What is the reason behind this?

The reason behind that is that OCI doesn’t preserve the hostname across reboots. By Default, OCI will update the hostname from the OCI metadata service.

Luckily, this behavior is configurable and you can change it.
There is a configuration file called: /etc/oci-hostname.conf, inside this file there is a parameter called “PRESERVE_HOSTINFO”, that you can set it to 2 to preserve the new name across reboots.
If you examined the different settings of this parameter:

So, If you set the PRESERVE_HOSTINFO to 2 or 3 and change the hostname as usual, it will not be changed after reboot.

As as reminder, below are the steps to change the hostname on Oracle Linux:

Thanks
Ahmed

Leave a comment