Setting a Persistent Hostname in Oracle Cloud (Oracle Linux )
When deploying virtual machines in Oracle Cloud Infrastructure (OCI), the cloud metadata service often manages hostname configuration. This can overwrite any manual hostname changes made on the instance after a reboot.
In this blog post, we'll walk through setting a custom hostname on an OCI instance running Oracle Linux 8.7 and ensuring it persists across reboots.
Manually set the hostname of your OCI instance and configure it so that your changes aren't lost during reboots or restarts.
Step 1: Set the Static Hostname
hostnamectl
command to define your new hostname:[root@omoicsso ~]# hostnamectl set-hostname omoicsso.oasiserp.com
You can verify the change by running:
[root@omoicsso ~]# hostnamectl
Static hostname: omoicsso.oasiserp.com
Icon name: computer-vm
Chassis: vm
Machine ID: e0251ef691f54fe7b98d3354af266d31
Boot ID: 333e7d37ec2b45d6942b50a9bf180b11
Virtualization: kvm
Operating System: Oracle Linux Server 8.7
CPE OS Name: cpe:/o:oracle:linux:8:7:server
Kernel: Linux 5.15.0-100.96.32.el8uek.x86_64
Architecture: x86-64
[root@omoicsso ~]#
At this point, the hostname has been changed — but it may not be persistent across reboots due to OCI's metadata-based management.
Step 2: Configure Hostname Persistence
OCI instances come with a special configuration file: /etc/oci-hostname.conf
.
Edit or verify the following setting:
[root@omoicsso ~]# cat /etc/oci-hostname.conf
# This configuration file controls the hostname persistence behavior for Oracle Linux
# compute instance on Oracle Cloud Infrastructure (formerly Baremetal Cloud Services)
# Set PRESERVE_HOSTINFO to one of the following values
# 0 -- default behavior to update hostname, /etc/hosts and /etc/resolv.conf to
# reflect the hostname set during instance creation from the metadata service
# 1 -- preserve user configured hostname across reboots; update /etc/hosts and
# /etc/resolv.conf from the metadata service
# 2 -- preserve user configured hostname across instance reboots; no custom
# changes to /etc/hosts and /etc/resolv.conf from the metadata service,
# but dhclient will still overwrite /etc/resolv.conf
# 3 -- preserve hostname and /etc/hosts entries across instance reboots;
# update /etc/resolv.conf from instance metadata service
PRESERVE_HOSTINFO=2
What Does This Do?
-
PRESERVE_HOSTINFO=2
tells the system to preserve your manually configured hostname even after a reboot. -
It prevents the OCI metadata service from overwriting your hostname, while still allowing it to update
/etc/resolv.conf
.
Final Check
After setting PRESERVE_HOSTINFO=2, your instance will retain the hostname even after a reboot.
You can test by rebooting:
Static hostname: omoicsso.oasiserp.com
Conclusion
Oracle Linux on OCI provides flexibility in hostname configuration — but only when you know where to look. Setting PRESERVE_HOSTINFO=2 ensures that your manual hostname configuration stays intact, avoiding surprises after restarts.
This is particularly useful in environments where:
-
Hostnames are used for licensing, monitoring, or DNS registration.
-
Manual management of infrastructure is part of your architecture.