Hostwinds Tutorials
Search results for:
Table of Contents
The hostname is the name your system uses to identify itself on a network. It's helpful when managing servers or working with multiple machines, as it shows up in SSH sessions, monitoring dashboards, system logs, and more.
This guide will walk you through checking and changing your hostname using methods compatible with most modern Linux distributions.
A hostname is a human-readable label given to a system for identification on a network. It usually looks something like web-01, db-server, or internal-proxy. There are three main types:
To see your system's current hostname, open a terminal and run:
hostnamectl
This command will give you a full picture of your system's identity and environment by displaying its static, transient and pretty hostnames.
Example output:
Static hostname: web-server-01
Icon name: computer-vm
Chassis: vm
Machine ID: 29d55dfb36c341e3bd95d3458b65c25c
Boot ID: f70b97e182e24b39b45de4db14bbfb18
Virtualization: kvm
Operating System: Ubuntu 22.04.3 LTS
Kernel: Linux 5.15.0-91-generic
Architecture: x86-64
What each of these lines mean:
If you just want to the hostname without all the system details:
hostname
Example output:
web-server-01
There are three common methods to change the hostname. The right one depends on your system setup and preferences.
Most modern Linux distributions using systemd (e.g., Ubuntu, Debian, Fedora, AlmaLinux, Rocky Linux) support this method.
sudo hostnamectl set-hostname new-hostname
Replace 'new-hostname' with your desired name (e.g., app-server-01).
Example:
sudo hostnamectl set-hostname app-server-01
sudo hostnamectl set-hostname "Application Server 01" --pretty
hostnamectl
You should see an output similar to this format:
Static hostname: app-server-01
Icon name: computer-vm
Chassis: vm
Machine ID: 29d55dfb36c341e3bd95d3458b65c25c
Boot ID: f70b97e182e24b39b45de4db14bbfb18
Virtualization: kvm
Operating System: AlmaLinux 9
Kernel: Linux 5.14.0-362.el9.x86_64
Architecture: x86-64
The updated hostname, displayed under Static hostname, is now visible across your desktop environments and status tools..
If your system doesn't use systemd, or if you prefer manual configuration, you can edit the hostname directly via config files.
These changes typically persist across reboots.
sudo nano /etc/hostname
Replace the existing hostname with your new one. For example, change:
web-server-01
to:
app-server-01
sudo nano /etc/hosts
Find the line that looks like this:
127.0.1.1 web-server-01
And update it to reflect the new hostname:
127.0.1.1 app-server-01
Important: make sure 127.0.0.1 localhost is still intact:
127.0.0.1 localhost
127.0.1.1 app-server-01
What this means and why it's important:
If you skip updating this file when changing the hostname, you might run into issues with services that rely on local name resolution.
For the change to take full effect, you'll need to reboot:
sudo reboot
After reboot, check the hostname to verify everything is working:
hostnamectl
This method provides a guided interface, a good choice if you're not comfortable with command-line editing.
sudo nmtui
Restart your system:
sudo reboot
Then confirm with:
hostnamectl
Regardless of the method, always verify your changes:
hostnamectl
And check:
hostname
Choosing a clear and consistent hostname makes it easier to manage and monitor your servers—especially in environments with multiple machines. Here are a few simple guidelines to follow:
Written by Hostwinds Team / August 31, 2018