Every Linux machine is required to have a hostname, which is usually configured during system installation. The hostname information is stored in the /etc/hostname file and is used to identify a system within a network, among other things.
You can view the current hostname of the system by viewing the content of the /etc/hostname file or by using the hostname command. Command prompts in Linux also normally display the system's hostname.
You can change the system's hostname by editing the /etc/hostname file or using the hostname command. The proper way, though, is to use the hostnamectl tool. hostnamectl avoids misconfiguration of the /etc/hostname file and ensures that the change is persistent after the system reboots.
user@host:~$ hostname host
user@host:~$ sudo hostnamectl set-hostname newhost
user@host:~$ hostname newhost
user@host:~$ cat /etc/hostname newhost
user@host:~$ bash user@newhost:~$
Comment anonymously. Login not required.