How to Change Hostname on Fedora 44

Last updated Sunday, May 17, 2026 5:25 pm Joshua James 5 min read

Duplicate or generic Fedora hostnames make SSH prompts, router leases, logs, and inventory records harder to trust. To change hostname on Fedora Linux, set a static name with hostnamectl, verify the saved value in /etc/hostname, and only touch /etc/hosts when a custom old-name entry is still present.

Fedora uses systemd’s hostname service on normal Workstation, Server, and SSH-managed systems. The static hostname is the persistent machine name, the pretty hostname is a display label, and the transient hostname is a runtime fallback that can come from network configuration.

Change Hostname on Fedora with hostnamectl

hostnamectl is the safest default method because it changes the running hostname and writes the persistent static hostname in one step. Fedora’s current syntax is hostnamectl hostname NAME; the older set-hostname form may still appear in older examples, but the documented form is clearer on current releases. The change does not require a reboot, although existing shells may keep showing the old prompt until you open a new session.

These commands need administrator access. If your account cannot use sudo yet, add it to Fedora’s wheel group with the guide to add a user to sudoers on Fedora before changing the system hostname.

Check the Current Fedora Hostname

Record the current hostname before changing it, especially on a remote server where the prompt, SSH bookmark, or monitoring label may still use the old value for a while.

hostnamectl hostname
cat /etc/hostname

The first line is the live hostname reported by systemd. The second line is the saved static hostname file Fedora reads at boot.

Choose a Valid Fedora Hostname

Use a static hostname that works as a DNS-style label: lowercase ASCII letters, numbers, and hyphens, with optional single dots between labels when you intentionally use a fully qualified domain name. Each label should start and end with a letter or number, and the Linux kernel hostname limit is 64 characters. Avoid spaces and underscores in the static hostname; use a pretty hostname when you need a human-friendly display name.

The systemd hostnamectl reference separates the static, pretty, and transient hostname roles. Most Fedora administration tasks, including SSH prompts and local scripts, should use the static hostname.

Set the Static Hostname on Fedora

Set the new static hostname with hostnamectl. Replace fedora-linux with the name you want this machine to use.

sudo hostnamectl hostname fedora-linux --static

The command is silent when it succeeds. If you run it over SSH, the current connection stays open; reconnect or open a new shell when you want the prompt and terminal title to refresh.

Verify the Fedora Hostname Change

Check the live hostname, the saved file, and the static hostname field. A clean change returns the same value from all three checks.

hostnamectl hostname
cat /etc/hostname
hostnamectl --static
fedora-linux
fedora-linux
fedora-linux

Check Local Name Resolution on Fedora

Fedora normally resolves the current hostname through the myhostname NSS module, so it does not need Ubuntu-style 127.0.1.1 host entries on a default install. Confirm the hostname lookup path before adding or editing local host aliases.

grep '^hosts:' /etc/nsswitch.conf
getent hosts "$(hostnamectl hostname)"

If getent returns one or more addresses for the new hostname, local resolution is working. If you previously added the old hostname to /etc/hosts, inspect the file and replace only that custom name. Leave the standard localhost lines unchanged.

sudo nano /etc/hosts

Set a Pretty Hostname on Fedora

A pretty hostname is a display label for people, not the machine name scripts and DNS-style lookups should depend on. Use it for a Fedora Workstation device label while keeping the static hostname short and shell-safe.

sudo hostnamectl hostname "Fedora Lab Workstation" --pretty
hostnamectl --pretty
Fedora Lab Workstation

Check both fields when you want to confirm the display name did not replace the static hostname.

hostnamectl status | grep -E 'Static hostname|Pretty hostname'
     Static hostname: fedora-linux
     Pretty hostname: Fedora Lab Workstation

Clear the pretty hostname later by setting it to an empty string.

sudo hostnamectl hostname "" --pretty

Change Fedora Hostname by Editing /etc/hostname

The file-based method is useful in rescue shells, stripped-down environments, or automation that writes the saved hostname directly. Editing /etc/hostname alone changes the boot-time value, so apply the file to the running kernel before verifying.

Write the New Hostname File

Use tee because a plain shell redirection would run before sudo receives permission to write the root-owned file.

printf '%s\n' 'fedora-linux' | sudo tee /etc/hostname
fedora-linux

Apply the Saved Hostname Without Rebooting

Apply the saved hostname to the running system with hostname -F. The -F option reads the hostname from the file you just wrote.

sudo hostname -F /etc/hostname

Confirm the live hostname, systemd hostname, and saved file now match.

hostname
hostnamectl hostname
cat /etc/hostname
fedora-linux
fedora-linux
fedora-linux

Temporarily Change Hostname on Fedora

The older hostname command can change the live kernel hostname for a short test. It does not update /etc/hostname, so the saved static hostname returns after reboot or after the next persistent hostnamectl change.

sudo hostname fedora-temporary
hostname
cat /etc/hostname
fedora-temporary
fedora-linux

The mismatch is expected: the first line is the temporary live hostname, while the second line is still the saved static hostname.

Restore the Previous Fedora Hostname

Rollback is the same operation as the original rename. Replace old-fedora-host with the previous static hostname you recorded before making changes.

sudo hostnamectl hostname old-fedora-host --static

Verify the restored hostname before closing a remote session. Both checks should return the previous name.

hostnamectl hostname
cat /etc/hostname

If you also changed a custom host alias, restore that entry in /etc/hosts. If the system is managed over SSH, keep the active session open until a new session connects with the restored name. For broader remote-access setup, use the Fedora guide to install and enable SSH on Fedora.

Troubleshoot Fedora Hostname Changes

hostnamectl Rejects the New Static Hostname

Spaces are invalid in a static hostname. If you try to set a static name with spaces, Fedora rejects it before changing the saved hostname.

sudo hostnamectl hostname 'bad name with spaces' --static
Could not set static hostname: Invalid hostname 'bad name with spaces'

Use hyphens for the static hostname, or set the friendly text as a pretty hostname instead.

sudo hostnamectl hostname fedora-lab --static
sudo hostnamectl hostname "Fedora Lab Workstation" --pretty

Hostname Changes Back After Reboot

If the hostname changes back after reboot, another layer is managing the name. Cloud images, cloned VM templates, DHCP-provided transient names, or provisioning tools can reapply their own values. Start by checking whether Fedora still has the static hostname you set.

hostnamectl status

If the static hostname is correct but a transient hostname also appears, the static name still wins for normal system identity. If the static hostname itself changes back, inspect the platform or image tool that provisions the machine before repeating the rename.

command -v cloud-init

If cloud-init is present on a Fedora cloud image, use the provider’s supported cloud-init settings instead of fighting the generated hostname after every boot.

Local Commands Cannot Resolve the New Hostname

Fedora normally resolves its own hostname through myhostname. If local tools complain that the hostname cannot be resolved, compare the current name, the NSS hosts line, and any custom hosts-file entry. Replace old-fedora-host with the previous hostname if you know it.

hostnamectl hostname
grep '^hosts:' /etc/nsswitch.conf
grep -nE 'old-fedora-host|fedora-linux|127\.0\.1\.1' /etc/hosts

No matching /etc/hosts line can be normal on Fedora when myhostname is present. A stale custom line is the real problem; update or remove the old name rather than changing localhost. If the failure is broader DNS lookup behavior instead of local hostname resolution, use the troubleshooting steps to fix could not resolve host errors.

SSH Prompt or Terminal Title Still Shows the Old Name

Existing shells can keep the old prompt text until they rebuild the prompt or start a new login session. Open a new terminal tab, reconnect over SSH, or run the shell’s prompt refresh path after verifying hostnamectl hostname returns the new name.

Conclusion

Fedora now uses a persistent static hostname, with an optional pretty name only for display. Keep the static name short and DNS-safe, leave default localhost entries alone, and recheck provisioning tools when a VM or cloud image keeps replacing the hostname.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: