Hostname is the machine name that has assigned during the installation of the OS. Not to be confused with the username, which is the user account login name. While there can be many user accounts on the system, there’s only one hostname and it’s the same for every user.
The shell prompt has this syntax,
user is the login name of the user account.
hostname is the physical machine name (mapped to 127.0.0.1).
directory is the current working directory.
$ indicates the regular user.
# indicates the super user.
The command hostname prints the host name of the machine which is apparent in the shell prompt.
[deepak@rhel7 ~]$ hostname rhel7
To change the hostname, simply pass the new hostname as argument to the hostname. And it requires super user privileges.
[deepak@rhel7 ~]$ sudo hostname dileep [sudo] password for deepak: [deepak@rhel7 ~]$ hostname dileep
Closing and opening the terminal confirms the changed hostname.
But this change is temporary. Once the system is shut down the hostname we set will be lost, just like the IP address set via ifconfig. To make it permanent, open and edit the file /etc/hostname. After editing it looks as follows.
[deepak@dileep ~]$ cat /etc/hostname dileep
Now reboot the system to confirm the new host name of the machine.