What is the command for host name?

The “hostname” command in Linux is used to check the system name that is assigned to a Linux machine. However, this command can also be paired up with other different flags for getting different outputs. We will try to throw light on some examples of the “hostname” command in Linux in this article.

General Syntax of the “hostname” Command:

The general syntax of the “hostname” command in Linux is shown below:

Here, you can replace “parameter” with any flags or options used with the “hostname” command. Some of those flags or options are also described in the examples below. However, if you want to execute the simple “hostname” command, you can also do that without stating any parameter.

Examples of Linux “hostname” Command:

For learning the usage of the “hostname” command in Linux, you can go through the following examples:

Example # 1: Check the Hostname of your Linux System:

This command is most commonly used for checking the hostname of your Linux system by running it in the manner shown below:

Our Linux system’s hostname is shown in the following image:

Example # 2: Check the IP Address against the Hostname of your Linux System:

You can also check the IP address that is assigned to your Linux machine against its hostname by using the “hostname” command with the “-i” parameter as follows:

The IP address against the hostname of our Linux system is shown in the image below:

Example # 3: Check the Fully Qualified Domain Name of your Linux System:

If you want to check the fully qualified domain name of your Linux system, then you can use the “-f” flag with the “hostname” command as follows:

The fully qualified domain name of our Linux system is shown in the image below:

Example # 4: Check the Alias of the Hostname of your Linux System:

At times, users also set aliases against the hostnames of their systems. If you want to check the alias against the hostname of your system (if it exists), then you can use the “-a” parameter with the “hostname” command as follows:

Since we had not set up an alias for our system’s hostname, therefore, we were presented with a blank output, as shown in the image below:

Example # 5: Check the Short Hostname of your Linux System:

If there is a dot in your hostname, then the short hostname refers to the portion of your hostname before that dot. You can display the short hostname of your Linux system by using the “-s” flag with the “hostname” command as follows:

Since we did not have a dot in our system’s hostname, therefore, the short hostname of our Linux system is the same as our actual hostname, which is shown in the image below:

Example # 6: Change the Hostname of your Linux System:

If you want to change the hostname of your Linux system, then you can also do that while using the “hostname” command in the following manner:

$ sudo hostname NewHostName

Here, you will have to replace NewHostName with any desired new hostname you want to set up for your Linux system. This command will not show any output on the terminal upon successful execution.

You can confirm if a new hostname has been set up for your system or not by executing the command shown below:

From the output of the above-mentioned command, it is quite evident that our hostname has been changed successfully, as shown in the following image:

Conclusion:

We discussed the six different examples of using the “hostname” command in Linux in this article. To learn more about the usage of this command in Linux, you can run the “hostname –help” command in your system’s terminal.

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
Show Linux Hostname

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
Show Hostname IP Addresses

To view the name of the DNS domain and FQDN (Fully Qualified Domain Name) of your machine, use the -f and -d switches respectively. And the -A enables you to see all the FQDNs of the machine.

$ hostname -d $ hostname -f $ hostname -A
Show Host DNS Names

To display the alias name (i.e., substitute names), if used for the host name, use the -a flag.

$ 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
Set Linux System 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.

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Toplist

Latest post

TAGs