How To Use HOSTNAME Command in Linux
In this tutorial, we explain how to use Hostname command in Linux in different ways.
The basic syntax for using this hostname command is:
hostname [options] [new_name]
When we use the hostname command without any option or argument, the result will be the current hostname and the domain names of the local machine.
The default hostname and domain in Linux is localhost.localdomain.
When we add a name as an argument, it will become the new hostname or selected computer name.
The root account can only make all changes to the hostname due to its administrative privileges or failing to precede the su command and the respective password.
We execute the hostname line:
When the host name is resolved, that is, it has a defined name, it is possible to display the IP addresses of the host name with the -y parameter and the -I option defines all the configured network interfaces and generates all the addresses as a result Network of the selected host:
hostname -i hostname -I
These options give us more administrative results, in this case, associated with the DNS.
We can use the parameters -f and -d , in simultaneous, and using the parameter -A it will be possible to see all the FQDN of the mentioned machine:
hostname -d hostname -f hostname -A
This command gives us the possibility to display the alias name.
If it is necessary to edit the name of the current machine, simply execute this syntax, hostname plus the new name of the computer and thus establish the desired name for it:
sudo hostname New_Name
We can see how the use of this command is simple but fully functional and practical for all administration tasks at the computer name level.