How to change the hostname for an OCI Compute Instance

Following are the steps that I followed to change the hostname of one OCI Compute Instance for one of my clients. Note that the operating system for this instance is Oracle Linux:

1. Use the hostnamectl utility to change the hostname

hostnamectl set-hostname new_hostname

2. Update the /etc/hosts file with the new name

[root@infodqmdm001 ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.17.15.112 new_hostname.app.oraclevcn.com new_hostname

3- Update the /etc/oci-hostname.conf, set the PRESERVE_HOSTINFO=2 so as to preserve the new name across reboots

vi /etc/oci-hostname.conf

PRESERVE_HOSTINFO=2

4- If necessary, edit the FQDN from OCI console GUI.

5- Check the file: cat /etc/sysconfig/network

    If the HOSTNAME is set, change it to the new name

6- Test using: hostnamectl

7- Reboot the machine and ensure the new hostname came after rebbot

Leave a comment