Log in
Build Your Site
Step-by-Step: How to Change Linux Hostname in 2025
Learn how to change your Linux hostname in 2025 with this comprehensive, step-by-step guide. Covers methods for Ubuntu, CentOS, Red Hat, and more.

Picture This: You’re managing a network of servers, each handling critical tasks for your business. Everything runs smoothly—until you realize two servers have nearly identical hostnames. Confusion ensues, errors multiply, and troubleshooting becomes a wild goose chase. That’s how powerful a simple hostname can be. Understanding how to change the hostname of Linux Ubuntu or Red Hat can prevent such issues from escalating.
In 2025, hostnames are more than just labels; they’re digital signposts that keep systems organized and networks in sync. They define how devices identify themselves across a network, impacting everything from communication protocols to system monitoring. Implementing the right procedures to change the hostname of Linux Ubuntu and Linux Red Hat ensures consistency and clarity throughout your network.
But what if your company rebrands, merges with another, or expands into new regions? Suddenly, those old server names become a mismatched relic of the past. Or maybe you’re optimizing your cloud infrastructure, restructuring network nodes, or implementing new security measures. Changing hostnames becomes essential—not just for clarity, but for maintaining operational integrity. And the good news? Updating a hostname in Linux, whether to change the hostname of Linux Ubuntu or Linux Red Hat, isn’t rocket science. Let’s dive in.

Understanding Hostnames in Linux
What is a hostname? Like the digital name tags of Linux systems, hostnames let other devices know who they are and how to interact with them. There are, however, three different kinds of hostnames in Linux. Let us dissect them: Understanding how to change the hostname of Linux Ubuntu or Linux Red Hat is crucial in effectively managing these different types.
Static, Transient, and Pretty Hostnames: What’s the Difference?
Static Hostname:
-
This is the permanent identifier assigned to the system. It’s stored in "/etc/hostname" and remains unchanged unless explicitly modified. Think of it as the system’s legal name—a constant that helps with consistent network identification.
Transient Hostname:
-
This is the kernel's temporary identifier. It might vary depending on dynamic circumstances, such as several network connections. Helpful for mobile devices connecting to several Wi-Fi networks or for transient network changes. When implementing procedures to change the hostname of Linux Ubuntu and Linux Red Hat, the transient hostname may also need adjustment.
Pretty Hostname:
-
This allows spaces and special characters, making for a human-friendly version. It's purely cosmetic, for use in GUIs or dashboards, and has no effect on networking. For example, a pretty hostname could be “Daito’s Laptop” instead of the static daito-laptop.
How They Interact:
-
When you update the static hostname, the transient hostname often adjusts to match, but they can be configured independently.
-
The pretty hostname is entirely separate—useful for user interfaces but irrelevant for system operations.
Hostname Conventions: Naming Best Practices
An improperly selected hostname could destroy network control. Here’s how to get it right:
Character Limitations:
-
Hostnames can only contain letters (
a-z
), digits (0-9
), and hyphens (-
). -
They must start and end with a letter or digit—no special characters or underscores.
-
Maximum length is 63 characters.
Naming Best Practices:
-
Be Descriptive: Include the function (e.g.,
web-server-01
), location (nyc-database
), or department (finance-backup
). -
Avoid Conflicts: Ensure unique names to prevent network confusion.
-
Stay Consistent: Adopt a naming scheme that’s logical and easy to understand at a glance.
-
Prioritize Readability: Keep it simple and easy to remember, especially for transient hostnames that may change frequently.
Before starting the actual hostname modification process, one must first grasp these principles. Let’s start by discussing how to change the hostname of Linux Ubuntu and change the hostname of Linux Red Hat effectively.
Checking Your Current Hostname
Before changing a hostname, you need to know what you’re working with. Fortunately, Linux makes it easy to check your current hostname using a few simple commands and file checks. Let’s dive in:
1. Using hostname
and hostnamectl
Commands
a)
hostname
Command:-
The quickest way to check your current hostname is by running:

-
This command displays the current hostname as a single string, e.g.,
server01
. -
It’s straightforward but limited—it only shows the static hostname without additional details.
b)
hostnamectl
Command:-
For more comprehensive information, use:

This command provides three key pieces of information:
Static hostname: The permanent name stored in
/etc/hostname
; Transient hostname: A temporary name assigned by the network or system;
Pretty hostname: The human-readable name, if configured.
-
Example output:

2. Viewing /etc/hostname
and /etc/hosts
Files
Beyond commands, two key configuration files provide deeper insights:
a)
/etc/hostname
-
This file stores the static hostname. To view it, run:

-
You’ll see a single line with the current hostname, e.g.,
server01
. -
If you plan to change the hostname manually, this is the file to edit.
b)
/etc/hosts
-
This file maps hostnames to IP addresses. Check it with:

-
A typical entry might look like this:

-
If you change the hostname, you must update this file to reflect the new name, preventing network conflicts and ensuring proper system identification.
3. Understanding the Output
Static vs. Transient
-
If they don’t match, the system may have been reconfigured or is dynamically assigning hostnames.
Pretty Hostname
-
Purely cosmetic, but useful for identifying devices in GUIs or user interfaces.
/etc/hosts
Mapping-
Ensures network services correctly associate the hostname with the local IP address.
Now that you know how to locate the current hostname, let’s move on to changing it safely and effectively.
Methods to Change Hostname in Linux
Changing the hostname of Linux can be done through various methods, depending on your system setup and preferred approach. Let’s explore the five most effective methods, starting with the recommended
hostnamectl
command for modern systems.a. Using hostnamectl
(Systemd-Based Systems)
hostnamectl
is the preferred method for changing hostnames on Linux distributions using systemd, such as Ubuntu, Fedora, CentOS 7+, and Red Hat 7+, which simplifies the process, allowing you to manage all three hostname types—static, transient, and pretty.Step-by-Step Instructions:
1. Check the Current Hostname:

-
This displays the current static, transient, and pretty hostnames.
2. Set the New Hostname:

-
Replace
new-hostname
with the desired name (e.g.,web-server-01
). -
This command updates the static hostname.
3. Set a Pretty Hostname (Optional):

4. Set a Transient Hostname (Optional):

5. Verify the Changes:

-
The output should now reflect the new static, transient, and pretty hostnames.
Advantages of
hostnamectl
:-
Unified command for managing all hostname types.
-
Automatically updates necessary system files (
/etc/hostname
and/etc/hosts
). -
Consistent across most systemd-based Linux distributions.
-
Prevents accidental mismatches between hostname types.
b. Editing Configuration Files Directly
If you prefer manual control or are working on a system without
hostnamectl
, you can directly edit the configuration files. This method is universal across most Linux distributions.1. Modify
/etc/hostname
:-
Open the file using your preferred text editor:

-
Replace the existing hostname with the new one. Example:

-
Save and exit (
CTRL + X
, thenY
, thenEnter
).
2. Update
/etc/hosts
Accordingly:-
Open the
/etc/hosts
file:

-
Locate the line containing the old hostname and update it:

-
Save and exit the file.
3. Apply and Verify the Changes:
-
Reboot the system to apply the new hostname:

-
Once the system is back online, verify the changes:

-
Ensure consistency across all outputs.
c. Using nmtui
(Network Manager Text User Interface)
If you’re more comfortable with a text-based interface,
nmtui
provides a user-friendly way to change the hostname and it is common for CentOS, Red Hat, Fedora, and other systems using NetworkManager.1. Launch
nmtui
:
-
This opens a graphical menu within the terminal.
2. Navigate to Hostname Settings:
-
Select Set System Hostname and press
Enter
. -
Enter the new hostname (e.g.,
db-server-01
). -
Confirm and exit the interface.
3. Apply the Changes:
-
Restart the NetworkManager to apply the changes:

-
Verify the hostname:

d. Using nmcli
(Command-Line Interface for Network Manager)
For users comfortable with command-line interfaces,
nmcli
offers a more scriptable way to handle hostname changes, especially on CentOS, Red Hat, and Fedora systems.1. Change the Hostname Using
nmcli
:
-
Replace
new-hostname
with the desired hostname.
2. Restart the Network Manager:

3. Verify the Change:

-
This command confirms the new hostname has been applied.
e. Temporary Hostname Change with hostname
Command
If you need to quickly test a hostname change without permanently modifying system files, the
hostname
command is a quick and effective method.1. Apply a Temporary Hostname:

-
The change takes effect immediately but will not persist after a reboot.
2. Verify the Temporary Change:

3. Limitations and Caveats:
-
Temporary changes do not update
/etc/hostname
or/etc/hosts
. -
Rebooting the system will revert to the previous hostname.
-
This method is ideal for testing purposes but not recommended for permanent changes.
Distribution-Specific Instructions
Different Linux distributions may slightly vary in how hostnames are managed and modified. Let's take a look at the breakdown of the most common methods for change hostmane of linux--Ubuntu/Debian, CentOS/RHEL/Fedora, Arch Linux, and SUSE/OpenSUSE.
a. Ubuntu/Debian
Ubuntu and Debian are systemd-based, making
hostnamectl
the go-to method for managing hostnames. However, manual file edits and GUI options are also available.Preferred Methods: Using
hostnamectl
and Editing Files1. Using
hostnamectl
:-
The quickest way to update the hostname:

-
To set a pretty hostname (optional):

-
Verify changes:

2. Editing
/etc/hostname
and /etc/hosts
:-
Open the
/etc/hostname
file:

-
Replace the old hostname with
new-hostname
. -
Update
/etc/hosts
to reflect the new hostname:

-
Change the relevant line:

-
Reboot the system to apply changes:

GUI Options (Ubuntu Only):
-
On Ubuntu Desktop, open Settings > About and click Device Name to update the hostname.
-
Alternatively, use GNOME Tweaks for a graphical interface to set the pretty hostname.
b. CentOS/RHEL/Fedora
CentOS, RHEL, and Fedora provide multiple methods for hostname management, including hostnamectl, nmtui, and nmcli.
1. Using
hostnamectl
:
2. Using
nmtui
:
3. Using
nmcli
:
4. Editing
/etc/sysconfig/network
(CentOS/RHEL 6 and earlier):
c. Arch Linux
Arch Linux gives users greater flexibility but requires manual configuration.
hostnamectl
is still available but is not the only method.1. Using
hostnamectl
:
2. Manual File Edits:

3. Special Considerations for Arch Linux:
-
Arch Linux often requires additional configuration in networking scripts and init systems, especially when using custom network managers.
-
Ensure that any network services or daemons are restarted after hostname changes to prevent conflicts.
d. SUSE/OpenSUSE
SUSE and openSUSE provide multiple methods, including the YaST configuration tool and command-line utilities.
1. Using YaST:

2. Command-Line Method:

3. Editing Configuration Files:

Automating Hostname Changes with Scripts
Manually changing the hostname of Linux across multiple servers can be tedious and error-prone. Automating the process with a Bash script not only saves time but also ensures consistency across your infrastructure. Here’s how to effectively implement hostname changes through scripting, integrate them into deployment processes, and address security considerations.
1. Sample Bash Script for Changing Hostname
Script:
change_hostname.sh

2. Integrating Hostname Changes into Deployment Processes
In environments where servers are frequently deployed or scaled up, integrating hostname changes into deployment scripts ensures that each new instance is correctly identified within the network.
Using Configuration Management Tools:
-
Tools like Ansible, Puppet, and Chef can automate hostname changes alongside other configuration tasks.
-
Example with Ansible Playbook:
playbook.yml:

Conclusion
Changing the hostname of Linux systems, whether it’s Linux Ubuntu, Red Hat, or Arch, involves methods ranging from the simple
hostnamectl
command to manual file edits and interactive tools like nmtui
. By understanding the differences between static, transient, and pretty hostnames, you can effectively manage system identifiers across various distributions, ensuring consistency and preventing network conflicts.For best practices, always verify changes using commands like
hostnamectl status
and update both /etc/hostname
and /etc/hosts
to avoid discrepancies. Implementing security measures in automated scripts and following structured deployment processes will minimize errors when you change the hostname of Linux servers, making your infrastructure more reliable and manageable.Written by
Kimmy
Published on
May 14, 2025
Share article
Read more
Experiences
Best Photography Websites That Spark Ideas: How AI Personalization is Changing Inspiration
May 14, 2025
Our latest blog
Experiences
May 14, 2025
Best Photography Websites That Spark Ideas: How AI Personalization is Changing Inspiration
Webpages in a minute, powered by Wegic!
With Wegic, transform your needs into stunning, functional websites with advanced AI
Free trial with Wegic, build your site in a click!