Linux hostname command

The hostname command in Linux is used to view or set the hostname of the system. The hostname is the unique name assigned to a device on a network.

To view the current hostname, open a terminal and type:


This command will display the current hostname of the system.

To set a new hostname, you can use the hostname command followed by the desired hostname. However, changing the hostname typically requires administrative privileges, so you might need to use sudo or run the command as the root user. Here’s an example:

sudo hostname new_hostname

Replace new_hostname with the desired hostname you want to set for the system.

After executing the command, the new hostname will be set. However, please note that this change will be temporary and will not persist across system reboots. To set a persistent hostname, you may need to modify system configuration files or use distribution-specific methods.

It’s worth mentioning that there are other hostname-related commands and configuration files depending on the Linux distribution you’re using. For example, in some distributions, you might find the /etc/hostname file that contains the system’s hostname.

If you need to change the hostname permanently or make further modifications, I recommend referring to the documentation or specific resources for your Linux distribution to ensure the proper and supported method is followed.