What Is a Pretty Hostname and How to Set It Up

September 22, 2021

Introduction

A hostname is the name of a computer system within a network. A pretty hostname avoids most of the limitations of other hostname types, giving users more freedom when naming their systems.

In this tutorial, we will cover different methods you can use to set up a pretty hostname for a Linux system.

What Is Pretty Hostname and How to Set It Up

Prerequisites

What Is a Pretty Hostname?

There are three types of hostnames:

  • Static hostname: The standard hostname set by the user.
  • Transient hostname: A dynamic hostname set by the system kernel. By default, it is the same as the static hostname, but DHCP and mDNS servers can change it on runtime.
  • Pretty hostname: A free-form hostname defined by the user, usually to describe the system to other users within the network.

Static hostnames follow the same restrictions as Internet domain names. They have a maximum length of 64 characters and allow the use of letters, hyphens (-), underscores (_), and periods only.

In contrast, pretty hostnames can use any valid UTF8 symbol and have few limitations for maximum length.

How to Set Up a Pretty Hostname

There are two methods to set up a pretty hostname:

  1. Using the hostnamectl command.
  2. Manually editing the /etc/machine-info config file.

Method 1: Using the hostnamectl Command

Use the hostnamectl Linux command to set up a pretty hostname with:

sudo hostnamectl set-hostname "[name]" --pretty

For instance, to set up phoenixNAP's test system as the new pretty hostname, use:

sudo hostnamectl set-hostname "phoenixNAP's test system" --pretty

Check your new hostname by using the hostnamectl command without any options:

hostnamectl
Setting up a new pretty hostname using the hostnamectl command

Method 2: Manually Setting Up a Pretty Hostname

Linux systems store pretty hostnames in the /etc/machine-info config file. The file also contains system information, such as icon names, chassis types, deployment environment, and system location.

Note: It is important to note that /etc/machine-info only generates once you change one of the settings it stores. If there haven't been any changes to these settings, this file will be absent from your system.

1. If the /etc/machine-info file is absent, start by creating it with:

sudo touch /etc/machine-info

2. Open the file with a text editor. In this example, we are using the Nano editor:

sudo nano /etc/machine-info

3. Add a new line that defines the pretty hostname:

PRETTY_HOSTNAME="[name]"

In this example, to set up phoenixNAP's test system as the pretty hostname, add:

PRETTY_HOSTNAME="phoenixNAP's test system"
Adding the new pretty hostname to the /etc/machine-info file

4. Press Ctrl+X to exit the Nano editor. Type Y and press Enter when prompted to save the changes you made.

5. Use the hostnamectl command to verify the new pretty hostname:

hostnamectl
Verifying the new pretty hostname

Conclusion

After following this tutorial, you should have been able to set up a pretty hostname on your Linux system. To learn more about manipulating with hostnames on a Linux system, check out our guide to the Linux hostname command.

Was this article helpful?
YesNo
Aleksandar Kovačević
With a background in both design and writing, Aleksandar Kovacevic aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
Next you should read
How to Change Hostname on Ubuntu 18.04
February 27, 2019

Learn The Simple Way How to Change Hostname on Ubuntu 18.04. Multiple options, including using Linux command line tools.
Read more
How to Change Hostname on Ubuntu 20.04
July 25, 2024

Hostname is a unique identifier of a computer on a network. This tutorial details ways in which you can change your Ubuntu 20.04 machine's hostname, using command line or GUI.
Read more
How to Change Hostname in Debian 10
August 11, 2021

You can change the hostname in Debian 10 (Buster) as the root user by using the built-in hostname command or editing related system files. learn how to change your hostname in this step-by-step tutorial.
Read more
How to Change or Set Hostname on CentOS 8 / RHEL 8
August 10, 2020

If you decide to change your hostname, you have multiple available options to do so. Follow the methods in this guide and you will successfully change the hostname on your CentOS8 / RHEL machine.
Read more