linux hostname change command

A hostname is a label assigned to a device connected to a computer network. It’s used to identify the device within the network. Hostnames are often human-readable and can be assigned to computers, printers, servers, or any other device connected to a network. They typically correspond to an IP address, which is the numerical address used to locate devices on a network. Hostnames are useful because they are easier to remember and use than IP addresses, especially in situations where multiple devices are connected to a network. For example, a hostname might be “my-computer” or “printer-1”.

Displaying the Current Hostname 

To display the current hostname of a Linux system, you can use the hostname command in the terminal. Simply open a terminal and type

Configure a persistent hostname

To configure a persistent hostname on a Linux system, you typically need to edit the /etc/hostname file and modify the /etc/hosts file. Here’s a step-by-step guide:

  1. Edit /etc/hostname: Open a terminal and use a text editor (like nano or vi) to edit the /etc/hostname file. Replace the existing hostname with the new desired hostname. For example:

Changing the Hostname 

To change the hostname invoke the hostnamectl command with the set-hostname argument followed by the new hostname. Only the root or a user with sudo privileges can change the system hostname.

For example, to change the system hostname to you would use the following command:

The hostnamectl command does not produce output. On success, 0 is returned, a non-zero failure code otherwise.

Finally, to verify that the hostname was successfully changed, once again use the hostnamectl command:


In this tutorial, we have shown you how to change the hostname of your Linux system. Depending on your Linux distribution and the virtualization type, additional steps may be required to complete the process.

1 thought on “linux hostname change command”

Leave a Comment