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.
- A system running a Linux distribution
- An account with sudo privileges
- Access to the terminal window
- Access to a text editor, such as Nano
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.
Note: If you are looking to change a static or transient hostname, follow one of our guides listed below:
How to Set Up a Pretty Hostname
There are two methods to set up a pretty hostname:
- Using the
- Manually editing the /etc/machine-info config file.
Method 1: Using the hostnamectl Command
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:
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:
In this example, to set up
phoenixNAP's test system as the pretty hostname, add:
PRETTY_HOSTNAME="phoenixNAP's test system"
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:
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.