Hostwinds Tutorials

Search results for:


Table of Contents


What Is a Hostname?
How to Check Your Current Hostname
Changing the Hostname
Method 1: Change Hostname Using hostnamectl (Recommended)
Step 1: Set the new hostname
Step 2 (Optional): Set a pretty hostname
Step 3: Verify the change
Method 2: Change Hostname by Editing Configuration Files Directly
Step 1: Edit /etc/hostname
Step 2: Edit the /etc/hosts file
Step 3: Reboot or apply changes
Method 3: Change Hostname Using nmtui (NetworkManager Text UI)
Step 1: Launch the tool
Step 2: Navigate
Step 3: Apply changes
Final Check: Confirm Your Changes
Tips for Hostname Selection

How to Change Your Hostname In Linux

Tags: DNS,  Linux 

What Is a Hostname?
How to Check Your Current Hostname
Changing the Hostname
Method 1: Change Hostname Using hostnamectl (Recommended)
Step 1: Set the new hostname
Step 2 (Optional): Set a pretty hostname
Step 3: Verify the change
Method 2: Change Hostname by Editing Configuration Files Directly
Step 1: Edit /etc/hostname
Step 2: Edit the /etc/hosts file
Step 3: Reboot or apply changes
Method 3: Change Hostname Using nmtui (NetworkManager Text UI)
Step 1: Launch the tool
Step 2: Navigate
Step 3: Apply changes
Final Check: Confirm Your Changes
Tips for Hostname Selection

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.

What Is a Hostname?

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:

Type

Description

Static hostname

Persistent hostname stored in configuration. Used by default across reboots.

Transient hostname

Temporary name set by the kernel or DHCP.

Pretty hostname

A cosmetic name, shown in some desktop environments or dashboards.

How to Check Your Current Hostname

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:

Field

What It Shows

Static hostname

This is the system's permanent hostname. It's what the machine is called across reboots unless changed

Icon name

Used by graphical environments to display an appropriate icon — often ignored on servers

Chassis

Describes the system's physical or virtual type: desktop, server, or VM

Machine ID

A unique identifier tied to the Linux OS installation

Boot ID

A unique ID that changes each time the system boots

Virtualization

Shows if the system is running in a virtual machine (e.g., kvm, vmware, or none)

Operating System

Your Linux distribution name and version

Kernel

The version of the Linux kernel currently running

Architecture

The system's processor type (e.g., x86-64 for 64-bit systems)

If you just want to the hostname without all the system details:

hostname

Example output:

web-server-01

Changing the Hostname

There are three common methods to change the hostname. The right one depends on your system setup and preferences.

Method 1: Change Hostname Using hostnamectl (Recommended)

Most modern Linux distributions using systemd (e.g., Ubuntu, Debian, Fedora, AlmaLinux, Rocky Linux) support this method.

Step 1: Set the new hostname

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

Step 2 (Optional): Set a pretty hostname

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

Step 3: Verify the change

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..

Method 2: Change Hostname by Editing Configuration Files Directly

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.

Step 1: Edit /etc/hostname

sudo nano /etc/hostname

Replace the existing hostname with your new one. For example, change:

web-server-01

to:

app-server-01

Step 2: Edit the /etc/hosts file

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:

  • 127.0.0.1 localhost: This is the loopback address. It always refers to "this machine" and should never be removed.
  • 127.0.1.1 app-server-01: This line links your hostname to the loopback network. It allows programs running locally to resolve your machine's name properly.

If you skip updating this file when changing the hostname, you might run into issues with services that rely on local name resolution.

Step 3: Reboot or apply changes

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

Method 3: Change Hostname Using nmtui (NetworkManager Text UI)

This method provides a guided interface, a good choice if you're not comfortable with command-line editing.

Step 1: Launch the tool

sudo nmtui

Step 2: Navigate

  • Select "Set system hostname"
  • Enter your new hostname (e.g., db-server-02)
  • Confirm and exit

Step 3: Apply changes

Restart your system:

sudo reboot

Then confirm with:

hostnamectl

Final Check: Confirm Your Changes

Regardless of the method, always verify your changes:

hostnamectl

And check:

hostname

Tips for Hostname Selection

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:

  • Use lowercase letters, numbers, and hyphens only
  • Avoid special characters and spaces (except in pretty hostnames)
  • Keep the name under 64 characters
  • Make it descriptive enough for easy identification in logs or dashboards

Written by Hostwinds Team  /  August 31, 2018