How to Change Hostname in Oracle Linux 8, 9 & 10
Changing the hostname on Oracle Linux looks trivial, and it is, until the name silently reverts after a reboot, sudo starts printing “unable to resolve host”, or an Oracle Database listener refuses to start because it still points to the old name. This guide covers every supported method on Oracle Linux 8, 9 and 10, explains how static, transient and pretty hostnames differ, and closes with a troubleshooting table for the problems that actually show up in production.
Table of Contents
- Quick Answer
- Understanding Hostname Types
- Where the Hostname Lives (Architecture)
- Prerequisites
- Method 1: hostnamectl (Recommended)
- Method 2: nmcli
- Method 3: Edit /etc/hostname Directly
- Method 4: Temporary Change with hostname
- Method Comparison
- Configure /etc/hosts and FQDN Correctly
- Keep the Hostname on Cloud and DHCP Systems
- Legacy: Oracle Linux 7 and 6
- Post-Change Checklist
- Troubleshooting
- FAQ
- Conclusion
Quick Answer
On Oracle Linux 8, 9 and 10, run:
sudo hostnamectl set-hostname ol-app01.example.com
hostnamectl status
The change takes effect immediately and survives reboots. Log out and back in to refresh your shell prompt. Then update /etc/hosts so the new name resolves locally (see the FQDN section).
Understanding Hostname Types
Linux with systemd tracks three separate hostnames. Knowing the difference explains most “why did my hostname revert?” problems.
| Type | Stored In | Purpose | Survives Reboot? |
|---|---|---|---|
| Static | /etc/hostname | The name the kernel is given at boot. This is the one you normally want to change. | Yes |
| Transient | Kernel (kernel.hostname) | The running name. Can be set by DHCP or the hostname command. | No |
| Pretty | /etc/machine-info | Free-form label with spaces and capitals, for humans and UIs. | Yes |
Naming rules for the static hostname:
- Use lowercase letters
a-z, digits0-9, and hyphens- - Do not start or end with a hyphen
- Maximum 63 characters per label, 253 characters for the full FQDN
- Avoid underscores; many DNS servers and Oracle tools reject them
Where the Hostname Lives (Architecture)
+--------------------------------+
| hostnamectl / nmcli / vi | <- your command
+---------------+----------------+
|
v
+--------------------------------+
| systemd-hostnamed | D-Bus service
+-------+---------------+--------+
| |
writes | | sets
v v
+----------------+ +------------------+
| /etc/hostname | | Kernel hostname |
| (static) | | (transient) |
+----------------+ +--------^---------+
|
+------------------+------------------+
| |
+-------+--------+ +---------+---------+
| NetworkManager | | DHCP / cloud- |
| (hostname-mode)|<-----------------| init may set it |
+----------------+ +-------------------+
Name resolution: /etc/hosts -> /etc/nsswitch.conf -> DNS
The key takeaway: systemd-hostnamed is the single writer. Tools like hostnamectl and nmcli general hostname both talk to it. Editing /etc/hostname by hand works, but the running kernel name will not update until a reboot or until you also run hostnamectl.
Prerequisites
- Oracle Linux 8, 9 or 10 (RHCK or UEK kernel, both behave identically)
- A user with
sudoor root access - Console or out-of-band access if you are renaming a remote production server (a typo in
/etc/hostscan break tools that depend on name resolution) - A planned FQDN, for example
ol-app01.example.com
Check your current state first:
hostnamectl
Example output:
amansah@localhost:~$ hostnamectl
Static hostname: localhost
Icon name: computer-vm
Chassis: vm ๐ด
Machine ID: 9b072365aca64539ae85970d11b8d49a
Boot ID: cd3dd72e8ab2492fb263315c6005e3f8
AF_VSOCK CID: 3019577692
Virtualization: vmware
Operating System: Oracle Linux Server 10.2
CPE OS Name: cpe:/o:oracle:linux:10:2:server
Kernel: Linux 6.12.0-204.92.4.2.el10uek.x86_64
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
Firmware Version: 6.00
Firmware Date: Thu 2020-11-12
Firmware Age: 5y 10month 1w 4d
Method 1: hostnamectl (Recommended)
hostnamectl is the standard, portable method. It updates the static hostname and the running kernel name in one step.
Set the static hostname
sudo hostnamectl set-hostname db01.bckinfo
Set a pretty hostname (optional)
sudo hostnamectl set-hostname "Oracle Linux DB Server 01 HomeLab" --pretty
Set each type explicitly
sudo hostnamectl set-hostname ol-app01.example.com --static
sudo hostnamectl set-hostname ol-app01.example.com --transient
--static only changes /etc/hostname; --transient only changes the running name. With no flags, static and transient are set together.
Verify
hostnamectl status
hostname
hostname -f
Expected result:
Static hostname: ol-app01.example.com
Pretty hostname: Oracle Linux App Server 01
Icon name: computer-vm
Clear a hostname
Passing an empty string removes the value and falls back to DHCP or the default:
sudo hostnamectl set-hostname "" --static
Method 2: nmcli
If the server is managed by NetworkManager (the default on Oracle Linux 8, 9 and 10), you can use nmcli.
sudo nmcli general hostname ol-app01.example.com
nmcli general hostname
Then restart the hostname service so all consumers pick up the change:
sudo systemctl restart systemd-hostnamed
Note:
nmcli general hostnamealso writes the static hostname throughsystemd-hostnamed. It is functionally equal tohostnamectl set-hostnameand is useful in scripts that already usenmclifor network configuration.
Method 3: Edit /etc/hostname Directly
This is the file-based method, handy for configuration management and image building.
echo "ol-app01.example.com" | sudo tee /etc/hostname
Apply it without rebooting:
sudo hostnamectl set-hostname "$(cat /etc/hostname)"
Or simply reboot:
sudo systemctl reboot
Warning: the file must contain a single line with the hostname only. Trailing spaces, comments or multiple lines cause unpredictable behavior.
Method 4: Temporary Change with hostname
The classic hostname command changes only the transient name. It is lost at reboot.
sudo hostname temp-test01
hostname
Use this only for quick tests. For anything permanent, use Method 1.
Method Comparison
| Method | Persistent | Immediate | Best For | Notes |
|---|---|---|---|---|
hostnamectl set-hostname | Yes | Yes | Everyday admin work | Recommended default |
nmcli general hostname | Yes | Yes | Scripts already using nmcli | Same backend as hostnamectl |
Edit /etc/hostname | Yes | After apply/reboot | Templates, Ansible, kickstart | Needs hostnamectl or reboot to apply live |
hostname <name> | No | Yes | Quick testing | Reverts on reboot |
Legacy /etc/sysconfig/network | Yes (OL6 only) | After restart | Old systems | Not used on OL7 and later |
Configure /etc/hosts and FQDN Correctly
Changing the hostname does not update /etc/hosts. If the new name does not resolve, sudo prints unable to resolve host and some Oracle and Java tools hang for several seconds on lookups.
Edit /etc/hosts:
sudo vi /etc/hosts
Recommended layout for a server with a static IP:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.21 ol-app01.example.com ol-app01
Rules worth following:
- Put the FQDN first, then the short name as an alias
- Map it to the server’s real IP, not
127.0.0.1(Oracle Database and Grid Infrastructure in particular expect this) - Keep the
localhostlines untouched
Verify resolution:
getent hosts ol-app01.example.com
hostname -f
hostname -s
hostname -d
ping -c 2 ol-app01.example.com
If you use DNS, also create the matching A record and PTR (reverse) record. Missing reverse DNS is a common cause of slow SSH logins and Kerberos or SMTP problems.
Keep the Hostname on Cloud and DHCP Systems
On Oracle Cloud Infrastructure (OCI) instances and other cloud images, the hostname can be reset at boot by cloud-init or by the DHCP lease. Symptom: you set the name, reboot, and the old one is back.
Fix 1: Tell cloud-init to preserve the hostname
sudo tee /etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg << 'EOF'
preserve_hostname: true
EOF
If /etc/cloud/cloud.cfg already contains preserve_hostname: false, the drop-in above overrides it because files in cloud.cfg.d are read after the main file. You can also change the value directly in cloud.cfg.
Fix 2: Stop NetworkManager from taking the name from DHCP
Create a drop-in:
sudo tee /etc/NetworkManager/conf.d/90-hostname.conf << 'EOF'
[main]
hostname-mode=none EOF sudo systemctl reload NetworkManager
hostname-mode | Behavior |
|---|---|
default | NetworkManager uses a DHCP/DNS-provided name only when no static hostname is set |
dhcp | Always take the hostname from DHCP |
dns | Use reverse DNS of the IP address |
none | Never touch the hostname; only /etc/hostname matters |
Fix 3: Do not send or accept a DHCP hostname on one connection
nmcli connection modify "System eth0" ipv4.dhcp-send-hostname no
sudo nmcli connection up "System eth0"
Replace System eth0 with your connection name from nmcli connection show.
Legacy: Oracle Linux 7 and 6
For completeness, these older releases behave differently:
Oracle Linux 7 supports hostnamectl exactly as above. The legacy HOSTNAME= line in /etc/sysconfig/network is ignored.
Oracle Linux 6 (end of life, migrate when you can) has no systemd:
sudo vi /etc/sysconfig/network
# HOSTNAME=ol-app01.example.com
sudo hostname ol-app01.example.com
sudo service network restart
If you manage a mixed fleet, our Rocky Linux vs Ubuntu command cheat sheet shows the same RHEL-family versus Debian-family differences for everyday admin tasks.
Post-Change Checklist
Renaming a host touches more than the kernel. Work through this list before calling the change finished.
Hostname changed
|
+--> /etc/hosts updated? -- no --> sudo warnings, slow lookups
+--> DNS A + PTR records updated? -- no --> SSH/Kerberos/SMTP issues
+--> Services restarted? -- no --> old name in logs/banners
+--> Apps & configs reviewed? -- no --> broken listeners/clusters
+--> Monitoring / CMDB updated? -- no --> ghost host in dashboards
1. Restart name-dependent services
sudo systemctl restart rsyslog
sudo systemctl restart sshd
sudo systemctl restart chronyd
Postfix and other mail services often cache the name in myhostname:
sudo postconf -e "myhostname = ol-app01.example.com"
sudo systemctl restart postfix
2. Review Oracle Database and Grid Infrastructure
Changing the hostname of a server that runs Oracle Database is not a one-line job. Check these before you rename:
| Item | What to Check |
|---|---|
listener.ora | The HOST = entry must match the new name or IP |
tnsnames.ora | Clients referencing the old hostname need updating |
LOCAL_LISTENER / REMOTE_LISTENER | Update if they use the hostname |
| Oracle Restart / Grid Infrastructure | Renaming a GI node is a documented, separate procedure; do not just run hostnamectl |
| Enterprise Manager agents | Re-discover or re-register the target |
| Host-bound tooling or licensing | Some tools bind to the hostname; verify with the vendor |
For standalone databases, stop the listener and database, change the hostname, fix listener.ora, then start again. For RAC or Oracle Restart, follow Oracle’s official documentation for your exact release.
3. Kubernetes and container hosts
If the server is a Kubernetes node, do not rename it in place. The node name is registered in the cluster; renaming leaves a NotReady ghost node. Drain, delete and re-join instead. See our guide on setting up a Kubernetes cluster with kubeadm on Rocky Linux 10, where the same RHEL-family steps apply to Oracle Linux.
For Docker hosts, a renamed host is harmless in most cases, but Swarm nodes need the same drain-and-rejoin treatment. Installation basics are in How to Install Docker on Rocky Linux 10 with SELinux.
4. Update external systems
- DNS (A and PTR records)
- Monitoring (Prometheus targets, Zabbix, Nagios)
- Configuration management inventory (Ansible, Puppet)
- CMDB or asset register
- Certificates that contain the old hostname in CN or SAN
- SSH
known_hostson clients (remove the old entry withssh-keygen -R oldname)
Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| Hostname reverts after reboot | cloud-init or DHCP overrides it | Set preserve_hostname: true and/or hostname-mode=none (see cloud section) |
sudo: unable to resolve host ol-app01 | New name missing from /etc/hosts | Add an IP FQDN shortname line to /etc/hosts |
| Prompt still shows old name | Shell not refreshed | Log out and back in, or run exec bash |
hostname -f returns short name only | No FQDN mapping in /etc/hosts or DNS | Put the FQDN first in /etc/hosts |
Failed to set hostname: Access denied | Not running as root, or polkit blocked | Use sudo; check you are not in a restricted shell |
Failed to connect to bus | systemd-hostnamed or D-Bus not running (containers, chroot) | Edit /etc/hostname directly instead |
hostname -d returns empty | Static name has no domain part | Set the FQDN: hostnamectl set-hostname name.domain |
| Name rejected or truncated | Invalid characters or label over 63 chars | Use only a-z, 0-9, - |
| Oracle listener fails to start or connect | listener.ora still has the old hostname | Update HOST= in listener.ora, then lsnrctl start |
Node shows NotReady in Kubernetes after rename | Node name changed under kubelet | Drain, delete and re-join the node |
Old name still in /var/log/messages | rsyslog cached the name | sudo systemctl restart rsyslog |
| Mail rejected for bad HELO | Postfix myhostname still old | postconf -e "myhostname=..." and restart Postfix |
Useful diagnostic commands
hostnamectl status
cat /etc/hostname
cat /etc/hosts
sysctl kernel.hostname
nmcli general hostname
systemctl status systemd-hostnamed
journalctl -u systemd-hostnamed --since "10 minutes ago"
grep -ri "hostname" /etc/cloud/ 2>/dev/null
FAQ
How do I change the hostname in Oracle Linux permanently?
Run sudo hostnamectl set-hostname your-name.example.com. This writes the static hostname to /etc/hostname, so it persists across reboots. Then update /etc/hosts.
Do I need to reboot after changing the hostname?
No. hostnamectl and nmcli general hostname apply the change immediately. Only a manual edit of /etc/hostname needs hostnamectl set-hostname "$(cat /etc/hostname)" or a reboot to take effect.
Why does my Oracle Linux hostname change back after reboot?
Usually cloud-init (preserve_hostname: false) or a DHCP-provided name is overwriting it. Set preserve_hostname: true in a cloud-init drop-in and use hostname-mode=none in NetworkManager.
What is the difference between static, transient and pretty hostnames?
Static is stored in /etc/hostname and survives reboots; transient is the running kernel value and may come from DHCP; pretty is a free-form display label stored in /etc/machine-info.
Can I use uppercase letters or underscores in the hostname?
Avoid both. Use lowercase a-z, digits and hyphens. Underscores are invalid in DNS hostnames and break many tools, including some Oracle components.
Is changing the hostname safe on a server running Oracle Database?
It is safe for the operating system, but you must update listener.ora, tnsnames.ora and any hostname-based settings, and Grid Infrastructure or RAC nodes require Oracle’s documented rename procedure.
Is the process different on Oracle Linux 10?
No. Oracle Linux 8, 9 and 10 all use systemd, systemd-hostnamed and NetworkManager, so the commands in this guide are identical.
Conclusion
On modern Oracle Linux, hostnamectl set-hostname is all you need to change the name itself. The work that separates a clean rename from a painful one is everything around it: an accurate /etc/hosts, matching DNS records, protection against cloud-init and DHCP overrides, and a careful review of Oracle Database, Kubernetes and monitoring dependencies.
Quick recap:
sudo hostnamectl set-hostname ol-app01.example.com- Update
/etc/hostswith IP, FQDN and short name - Add
preserve_hostname: trueon cloud instances - Restart affected services and update DNS
- Verify with
hostnamectl statusandhostname -f
Managing several distributions? Continue with the Rocky Linux vs Ubuntu command cheat sheet for a side-by-side view of everyday sysadmin commands.







