Setting a proper hostname and Fully Qualified Domain Name (FQDN) is one of the first configuration tasks on any new RHEL 8 server. A correct hostname ensures that system logs, email delivery, and network services identify your machine accurately. On RHEL 8, hostnamectl from systemd provides a clean, persistent way to manage hostname settings without editing files directly. This guide walks through setting a static hostname, configuring the FQDN via /etc/hosts, and verifying resolution with standard tools.

Prerequisites

  • A running RHEL 8 server with root or sudo access
  • Basic familiarity with the terminal and a text editor such as vi or nano
  • An understanding of your desired hostname and domain (e.g., web01.example.com)

Step 1 — Check the Current Hostname

Before making changes, inspect the current hostname configuration to understand what is already set. hostnamectl reports three hostname types: static (persisted across reboots), transient (set at runtime by the kernel or DHCP), and pretty (a free-form UTF-8 label).

hostnamectl status

Also confirm what the kernel currently reports:

hostname
hostname -f

If hostname -f fails with hostname: Name or service not known, your FQDN is not yet resolvable — that is corrected in the steps below.

Step 2 — Set a Static Hostname with hostnamectl

Use hostnamectl set-hostname to assign a new static hostname. Replace web01 with your desired short hostname. The change takes effect immediately and persists after reboot by writing to /etc/hostname.

sudo hostnamectl set-hostname web01

To set a pretty name alongside the static name (optional, useful for display in management tools):

sudo hostnamectl set-hostname "Web Server 01" --pretty

Confirm the change:

hostnamectl status

Step 3 — Configure the FQDN in /etc/hosts

For the system to resolve its own FQDN (required by many services such as Postfix, Kerberos, and Java applications), you must map the server’s primary IP address to both the FQDN and the short hostname in /etc/hosts. DNS is authoritative for external resolution, but /etc/hosts provides local resolution that works even without a DNS server reachable.

Open /etc/hosts in your editor:

sudo vi /etc/hosts

Add or update the line for your server’s IP. The FQDN must appear first, followed by the short hostname:

192.168.1.10  web01.example.com  web01

Do not remove the existing 127.0.0.1 localhost and ::1 localhost lines.

Step 4 — Verify FQDN Resolution

After updating /etc/hosts, verify that both short hostname and FQDN resolve correctly from the local system. The hostname -f command queries the OS name-resolution stack, which checks /etc/hosts before DNS (per the default /etc/nsswitch.conf order).

hostname
hostname -f
dnsdomainname

hostname should return web01, hostname -f should return web01.example.com, and dnsdomainname should return example.com. You can also use getent hosts web01.example.com to confirm the hosts file entry is being read.

Step 5 — Update Hostname via NetworkManager (Optional)

If your system uses NetworkManager and you want it to be aware of the hostname change, you can also set it through nmcli. This is particularly useful in environments where NetworkManager manages DNS and DHCP updates.

sudo nmcli general hostname web01.example.com
sudo systemctl restart systemd-hostnamed

Check the NetworkManager-persisted hostname:

nmcli general hostname

Step 6 — DNS vs /etc/hosts: Choosing the Right Approach

For a single server or a small lab, /etc/hosts is sufficient for FQDN resolution. In production environments with multiple servers, rely on DNS instead. Register an A record for your server’s IP in your DNS zone (e.g., web01.example.com. IN A 192.168.1.10) and ensure the reverse PTR record is also set. With DNS in place, you can remove the /etc/hosts entry and rely entirely on the nameserver. Verify DNS-based FQDN resolution with:

dig +short web01.example.com
host web01.example.com

Conclusion

You have set a static hostname on RHEL 8 using hostnamectl, configured the FQDN in /etc/hosts, and verified resolution with hostname -f and dnsdomainname. Your system will now correctly identify itself in logs, network communications, and service configurations that depend on the FQDN. For production deployments, complement the local /etc/hosts entry with proper forward and reverse DNS records.

Next steps: How to Sync Time with Chrony on RHEL 8, How to Configure Automatic Security Updates on RHEL 8, and How to Manage Users and Groups on RHEL 8.