Change Hostname In Linux

The hostname is used to identify and name a Linux system. The hostname is generally set during the operating system installation process. But the hostname is just a configuration that can be changed or set later In this tutorial we examine different ways and methods to change the hostname in Linux like Debian, Ubuntu, CentOS, Fedora, RHEL, Mint, etc. via the command line interface or GUI.

Display Current Hostname

Before changing the hostname we can display the current hostname with the hostname command.

$ hostname
ubuntu

Alternatively, we can use the hostnamectl command in order to print the current hostname.

$ hostnamectl
ubuntu

Change Hostname with hostnamectl Command

The hostnamectl command is specifically created to manage hostname. We can provide the new hostname to the hostnamectl command as a parameter to set it as the new hostname. In the following example, we set the hostname as “01.linuxtect.com”.

$ hostnamectl 01.linuxtect.com

Change Hostname with hostname Command

Before the hostnamectl command the hostname command was used to change the hostname. We can provide the new hostname to the hostname command as a parameter to change.

$ hostname 01.linuxtect.com

Change Hostname via /etc/hostname File

Most Linux distributions store the hostname information in the /etc/hostname file. The “/etc/hostname” is just a simple text file. So we can open the “/etc/hostname” file and change the hostname.

$ nano /etc/hostname

Leave a Comment