How to set or change the host name in Linux

By default, the system host name during installation settings, or if you want to create a virtual machine, when you start it will dynamically allocated to instances, but sometimes you need to change it.

This tutorial will guide you change the host name in Linux process, without having to reboot the system. This tutorial method is applicable to any modern Linux distributions use of systemd.

What is the host name

Host name is the label assigned to the machine, a computer on the network identification. Each device in the network should have a unique host name.

The host name can be a simple string of alphanumeric characters, and hyphens are included. If the computer is connected to the Internet (such as Web or mail server), it is recommended to use a fully qualified domain name (FQDN) as the system host name. The FQDN consists of two parts, the host name and domain name.

Displays the current hostname

In the use systemd Linux system, the hostnamectl command can be used to query and change the hostname and related settings on a given computer.

To view the current host name, please call the command hostnamectl without any parameters:

System host name highlighted in the figure below:

How to set or change the host name in Linux

Change the hostname

To change the host name, use hostnamectl new hostname set-hostname argument followed. Only the root user or have sudo privileges can change the system host name.

This command does not generate an output hostnamectl. After a successful return 0, otherwise non-zero fault code.

Finally, to verify that the host name has been changed successfully, use hostnamectl command again:

The new system host name and other system information (such as the kernel version) will be displayed on the terminal.

How to set or change the host name in Linux

in conclusion

In this tutorial, we show you how to change the hostname of a Linux system. Depending on your Linux distribution and virtualization type, you may need to perform additional steps to complete this procedure.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159987.htm