Computers are assigned with a name as we do for humans beings. This is called hostname in computer world. So how to assign a hostname to a Linux system? Its very much simple. Before doing this we should know every task in Linux can be done in two ways :
1. Temporary way(once you boot your system the changes made in this way will go away)
2. Permanent way(Changes made in this way will be retained even after rebooting of the system).
Before changing the hostname, check what is your present system name by using hostname command
#hostname
This command will show present system name.
Now we will see how to assign a host name to a linux machine in both(temporary as well as permanent) ways.
Temporary way : Use hostname command to change the host name
#hostname your-system-nameExample :
#hostname office-laptop.example.com
Permanent way : Change hostname in Redhat/CentOS/Fedora :
Edit /etc/sysconfig/network file, use HOSTNAME variable in that file to denote hostname.
#vi /etc/sysconfig/network
HOSTNAME=office-laptop.example.com
Save the file and exit
Then your hostname is changed permanently to your desired name.
Change hostname in Ubuntu/Debian :
Edit /etc/hostname, just write down what is your hostname in to that file.
#vi /etc/hostname
office-laptop.example.com
Save the file and exit
Then your hostname is changed permanently to your desired name.