A server’s hostname is its identity on the network. The fully qualified domain name (FQDN) combines the short hostname with the DNS domain, forming an address like web01.example.com. Many services depend on a correctly configured hostname and FQDN to function properly: email servers use the FQDN in SMTP HELO greetings (incorrect values cause delivery rejections), TLS certificate Common Names must match the FQDN, Kerberos and LDAP authentication rely on hostname resolution, and monitoring tools like Nagios and Zabbix use hostnames to identify which server is reporting metrics. Getting this right at server setup time prevents obscure failures later.

This guide covers setting the static hostname on RHEL 9, configuring the FQDN in /etc/hosts, verifying DNS resolution, understanding the difference between the static, transient, and pretty hostname types, and avoiding common pitfalls with cloud-init overwriting your hostname on reboot.

Prerequisites

  • RHEL 9 server with root or sudo access
  • A domain name you control (or a private domain for internal use)
  • Access to your DNS provider or internal DNS server if you want external resolution

Step 1 — Understand Hostname Types in systemd

RHEL 9 uses systemd-hostnamed to manage three hostname types:

  • Static hostname — stored in /etc/hostname, persists across reboots. This is what you almost always want to set.
  • Transient hostname — a temporary hostname provided by DHCP or mDNS. Overrides the static hostname if set, but is lost on reboot. Cloud instances often receive a transient hostname from the DHCP server on first boot.
  • Pretty hostname — a free-form descriptive string that can include spaces and Unicode characters: “Web Server 01 (Production)”. Used only by GUI tools; never used for network operations.

View all three:

hostnamectl

Step 2 — Set the Static Hostname

Use hostnamectl to set the hostname. The --static flag writes to /etc/hostname:

hostnamectl set-hostname web01.example.com

This command also sets the transient hostname in the running kernel immediately — no reboot required. Verify:

hostnamectl
hostname
hostname --fqdn

The hostname --fqdn command should return web01.example.com. If it returns only web01, the FQDN portion must be configured in /etc/hosts (Step 3).

Step 3 — Configure /etc/hosts for Local FQDN Resolution

Even if you have DNS, /etc/hosts must contain the server’s own FQDN. Many services perform a reverse lookup on the server’s IP and expect to get the FQDN back. Without this entry, hostname --fqdn and dnsdomainname return incomplete results:

vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# Set the server's own IP with FQDN first, then short name second
203.0.113.10  web01.example.com web01

Use the server’s actual public or private IP address (the one other machines reach it on), not 127.0.0.1. Using the loopback address for the FQDN is a very common mistake that causes email, Kerberos, and SSL issues.

Verify FQDN resolution now works:

hostname --fqdn
dnsdomainname

Step 4 — Create or Update the DNS A Record

For external DNS, log into your DNS provider and create an A record:

web01.example.com.  IN  A   203.0.113.10

If you also need reverse DNS (PTR record) for email deliverability, configure it in your cloud provider’s control panel (many cloud providers call it “reverse DNS” or “PTR record” in the IP management section):

10.113.0.203.in-addr.arpa.  IN  PTR  web01.example.com.

After TTL propagation (typically 5 minutes to a few hours), verify external resolution:

dig web01.example.com +short       # Should return 203.0.113.10
dig -x 203.0.113.10 +short        # PTR — should return web01.example.com.

Step 5 — Configure the DNS Search Domain

For servers in a private cluster, configure the DNS search domain so that short names like db01 resolve to db01.internal.example.com automatically. On RHEL 9 with NetworkManager:

# Identify the active connection name
nmcli connection show

# Set the DNS server and search domain
nmcli connection modify "System eth0" ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection modify "System eth0" ipv4.dns-search "example.com internal.example.com"

# Apply the changes
nmcli connection up "System eth0"

Verify:

cat /etc/resolv.conf

Step 6 — Prevent Cloud-Init from Overwriting the Hostname

On cloud instances (AWS, Google Cloud, Azure, DigitalOcean), cloud-init runs on every boot and can reset the hostname to the DHCP-assigned value, undoing your changes. Disable this behaviour:

vi /etc/cloud/cloud.cfg

Find the manage_etc_hosts and set_hostname lines and disable them:

manage_etc_hosts: false
# Comment out or set to false:
# - set_hostname

Or create a cloud-init override file:

cat > /etc/cloud/cloud.cfg.d/99_hostname.cfg << 'EOF'
preserve_hostname: true
manage_etc_hosts: false
EOF

Step 7 — Set a Pretty Hostname (Optional)

For larger teams with many servers, a descriptive pretty hostname helps in GUI management tools:

hostnamectl set-hostname "Primary Web Server (Production EU)" --pretty

The pretty hostname is stored in /etc/machine-info as PRETTY_HOSTNAME.

Verification

# Full hostname info
hostnamectl

# FQDN from hostname command
hostname --fqdn

# Domain part only
dnsdomainname

# Forward DNS resolution
host web01.example.com

# Reverse DNS resolution
host 203.0.113.10

# /etc/hostname
cat /etc/hostname

# /etc/hosts entry
grep web01 /etc/hosts

Troubleshooting

  • hostname –fqdn returns only the short name — the FQDN is not in /etc/hosts. Add the entry as described in Step 3, with the actual IP address (not 127.0.0.1).
  • Hostname reverts to cloud provider value after reboot — cloud-init is overwriting it. Follow Step 6 to disable cloud-init hostname management.
  • Email server rejects messages citing bad HELO hostname — the SMTP daemon is sending the short hostname instead of the FQDN. Ensure the FQDN is in /etc/hosts and that hostname --fqdn returns the correct value. Then restart your mail daemon.

Security Considerations

  • Use a meaningful, predictable hostname scheme across your fleet (e.g., purpose-region-sequence.domain.com: web-eu-01.example.com). Consistent naming makes audit logs, access controls, and certificates easier to manage.
  • Do not use hostnames that reveal internal architecture details in publicly accessible DNS records. Use generic names for public-facing servers.

Conclusion

Your RHEL 9 server now has a correctly set static hostname, FQDN, and DNS configuration. The FQDN is in /etc/hosts for reliable local resolution, DNS records are in place for external lookups, and cloud-init is prevented from overwriting your settings on reboot. This foundation is a prerequisite for TLS certificates, email delivery, and cluster membership.

Next steps: How to Sync Time with Chrony on RHEL 9, How to Request a Free TLS Certificate with Certbot on RHEL 9, and How to Configure Postfix for Email Delivery on RHEL 9.