Dec 05, 2025
Aris S. & Noviantika G.
5min Read
A Linux hostname identifies systems within a network, enabling them to identify and communicate with one another correctly. Assigning a unique hostname is crucial for network management to prevent multiple devices from sharing the same identity, which can cause conflicts and errors.
There are different ways to change a hostname in Linux:
You can also change the hostname temporarily or permanently, depending on your needs.
To check your current Linux system’s hostname, use the hostname or hostnamectl commands in your terminal.
The hostname command provides a quick look at the active system name:
hostname
The output will show your system’s current hostname:
myserver.example.com
For more details, use hostnamectl. This command can reveal different types of hostname:
You can run hostnamectl by itself without any flags or parameters:
hostnamectl
The output will display detailed information about your system, including its hostnames:
Static hostname: hostinger-vps Pretty hostname: Hostinger VPS Server Icon name: computer-vm Chassis: vm Machine ID: 45598cbdb6ee462e8696166b520fe788 Boot ID: 99526e56aeea45c2a0f3b2ffaaffe9d9 Virtualization: kvm Operating System: Ubuntu 22.04 LTS Kernel: Linux 5.15.0-101-generic Architecture: x86-64
Note that the transient hostname will appear only after you set a temporary hostname. You can explicitly tell hostnamectl to check it like this:
hostnamectl --transient
The above command will output only the transient hostname of your system. If you haven’t set up the temporary hostname, however, it’ll simply print the static hostname.
Permanently changing the hostname of your Linux system ensures that the new identity persists after a reboot. You typically do this when setting up a new VPS whose services require persistent communication, such as mail or web applications.
The easiest way to do it is by running the hostnamectl command:
sudo hostnamectl set-hostname new-host-name
sudo nano /etc/hosts
127.0.0.1 localhost 127.0.1.1 new-host-name
hostnamectl
Important! If your /etc/hosts file only contains localhost and not the old hostname, you don’t need to update it.
This method works for modern Linux distributions that use systemd. If your distro uses another init system, you can change the hostname by editing the configuration file manually.
You can manually edit configuration files to change the hostname on any Linux system. This is particularly useful for legacy distributions or when hostnamectl is unavailable:
sudo nano /etc/hostname
At this point, your hostname is updated. However, you’ll need to complete additional steps if you use a cloud system like a VPS hosting solution, because the provisioning service, like cloud-init, might reset the settings after reboot. Here’s how to preserve the new hostname:
sudo nano /etc/cloud/cloud.cfg
preserve_hostname: true
sudo reboot
Once your system finishes restarting, check the /etc/hostname file to verify that the change has been applied:
cat /etc/hostname

If you are changing your hostname as part of broader network maintenance or prefer using an interactive interface, use nmtui. This works similarly to hostnamectl but has an intuitive menu and more network-related options.
Install the tool before proceeding, as it’s not pre-installed in all Linux distributions. To do it on a Debian-based operating system like Ubuntu, run:
sudo apt install network-manager
Meanwhile, run the following if you use Red Hat Enterprise Linux-based distros like CentOS and AlmaLinux:
sudo dnf install NetworkManager-tui
Now, change your hostname using nmtui:
sudo nmtui

hostnamectl
If you want a more interactive method, change your system hostname via your hosting control panel.
Hostinger VPS users can change their server’s hostname directly from hPanel without using the command line. This method is the most beginner-friendly and simple because you don’t need to access your VPS’s terminal. Here’s how to do it:

This process updates the configuration permanently. Once the change takes effect, you’ll see it reflected in the VPS details section.
Alternatively, you can ask Kodee, our AI assistant, to change the hostname for your server like so. Remember to replace old-hostname and new-hostname with their actual values:
Change the hostname of my old-hostname VPS to new-hostname.

Important! If you update your VPS hostname via hPanel or Kodee, the change might not be reflected immediately due to the browser cache. However, it should be updated in the background, which you can check using commands via the terminal.
To temporarily change the hostname of your system, use the hostname command followed by your desired hostname.
sudo hostname temporary-name
To verify the change, run this command:
hostname
If the change is successful, your terminal will print the new static hostname. This temporary hostname will revert to the value stored in /etc/hostname after you reboot the system.
This method is helpful for quickly testing network scripts or debugging session-specific issues that require a hostname change without altering the permanent server configuration.
After changing the hostname of your Linux server, you should ensure that your connection protocols and network services align with the new identity. Two of the most important steps after updating your hostname are:
Changing the hostname is typically a part of a bigger network configuration. While doing so, it’s recommended to implement other security practices, such as changing the SSH port on your VPS, to further safeguard your system from various cyberattacks.