hostname : NIX class
Atul.Singh 270002HUVT Visits (1394)
The hostname command is used to show or set a computer's host name and domain name. It is one of the most basic of the network administrative utilities.
A host name is a name that is assigned to a host that uniquely identifies it on a network and thus allows it to be addressed without using its full IP address. Domain names are user-friendly substitutes for numeric IP addresses.
The basic syntax for the hostname command is
1. View your hostname
hostname command without any argument will return the name of your system.
2. Change hostname from command line
When a name is provided as an argument, it becomes the new host name. A change in the host name can only be performed by the root. To change the system name, do the following. Please note that this is only temporary. When you reboot the system, this hostname will not be used.
# hostname atul
To change the hostname permanently, modify the /etc/hostname file.
# vi /etc/hostname
3. Change hostname (get name from a file)
Use option -F to specify a filename. The name of the host will be picked-up from this filename and set appropriately.
# cat /hom
# hostname -F /hom
4. To fetch the short name of host
The -s option displays the short host name, which is the part of the name to the left of the first dot
# hostname -s atul