What Is a Pretty Hostname and How to Set It Up

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.

原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/224511.html

(0)
上一篇 2022年1月7日 16:35
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论