Saturday, June 1, 2024

Change Instance Hostname Permanently on OCI Oracle Cloud

I noticed that when I changed the hostname in OCI compute instance and when the server was rebooted  the instance hostname changed back to the default hostname.

Followed below steps to permanently preserve the hostname even after the server got rebooted.

Do all the below steps as root user. 

Step 1. Update this file /etc/oci-hostname.conf set the value of PRESERVE_HOSTINFO to 2.

$ vi /etc/oci-hostname.conf

PRESERVE_HOSTINFO=2

This change will be persistent across reboots.

Step 2.Edit /etc/sysconfig/network Here in this file change the parameter value for "hostname"

# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=<new_hostname> ← — — — — Update this value and set the name of server to be preserved. 

Step 3.Update the /etc/hostname file with the below command.

$ hostnamectl set-hostname <new_hostname>

This way even after the server is rebooted it will preserve the new hostname and will not revert back.