A hostname command is used to view a computer’s hostname and domain name (DNS) (Domain Name Service), and to display or set a computer’s hostname or domain name.
A hostname is a name that is given to a computer that attached to the network that uniquely identifies over a network and thus allows it to be accessed without using its IP address.
The basic syntax for the hostname command is:
# hostname [options] [new_host_name]
In this short article, we will explain 5 useful hostname command examples for Linux beginners to view, set or change Linux system hostname from the Linux command-line interface.
If you run hostname command without any options, it will displays the current host name and domain name of your Linux system.
$ hostname tecmint
If the host name can be resolved, you can display the network address(es) (IP address) of the host name with the
-i flag and the
-I option establishes all configured network interfaces and shows all network addresses of the host.
$ hostname -i $ hostname -I
To view the name of the DNS domain and FQDN (Fully Qualified Domain Name) of your machine, use the
-d switches respectively. And the
-A enables you to see all the FQDNs of the machine.
$ hostname -d $ hostname -f $ hostname -A
To display the alias name (i.e., substitute names), if used for the host name, use the
$ hostname -a
Last but not least, to change or set hostname of your Linux system, simply run the following command, remember to replace “NEW_HOSTNAME” with the actual hostname that you wish to set or change.
$ sudo hostname NEW_HOSTNAME
Note that the changes made using the above command will only last until the next reboot. Under systemd – system and service manager, you can use the hostnamectl command to permanently set or change your system hostname as explained in the following articles.
That’s It! In this short article, we explained 5 hostname command examples for Linux newbies. If you have any questions, use the feedback form below to reach us.