The hostname is very important Linux command that you can find useful many times. If you are reading this article, for sure, you are using Linux system. Here you can get all the Linux hostname commands that you need to run every day.
The host is nothing but your Linux system. And hostname is identity given to your system.
The hostname is useful when you want to connect your system to another system. To identify each system on the network, every system has been given hostname as identity. Hostname of the system is unique over the connected network.
Hostname command is used to get the system hostname as well as the DNS (Domain Name System) of the system.
Hostname command has its syntax.
The syntax for changing the hostname:
hostname [options] [new_host_name]
Each of the commands is explained in required detail for better understanding.
Use the hostname command without any option.
It is also called as the domain name of the system.
As I told you earlier, the hostname is unique over the connected network, there is corresponding IP address associated with hostname.
The hostname needs to resolve to get IP address which can be inferred from the hostname command along with
Or, you can use…
You can also find the IP address of the Linux system using
ifconfig. But, command ifconfig gives a large list of IP addresses. If you need only IP address you can just use
hostname -i command. It’s easy.
-d option to get the DNS name of the system.
Above command only give DNS name. It does not specify the exact location of the system in a hierarchy of DNS. To locate the exact location, you need a Fully qualified domain name (FQDN).
-f option with hostname command.
This command will return the complete and exact location of the system in DNS hierarchy.
To see all the FQDN of the system use option
There can be an aliased name for your hostname. Use
-a flag with hostname command.
Additional read: Linux Command to check the Serial Number
It is an easy and simple command.
sudo hostname <new_hostname>
You need super privilege for changing the hostname of the system.
If you try to get the IP address corresponds to the hostname, you may get some time error as…
hostname: Temporary failure in name resolution
Hostname command changes only persist until you reboot your Linux system.
There is a way to make the changes permanent if you wish.
Use a command
Before you leave…
You can explore and find more hostname commands using help option.
There are many other options you can use with hostname. You can get all the options by running a command
All the above-mentioned commands are tested on Ubuntu system and will work with any other Linux distribution.
That’s all from this quick post on Linux hostname command and examples. These are the very useful command related to the hostname. If you have any query related to the Linux command, let’s discuss in the comment.