7 Linux Hostname Commands with Example | You should Know

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.

Command hostname syntax:

Hostname command has its syntax.

hostname [option]

The syntax for changing the hostname:

hostname [options] [new_host_name]

7 Linux Hostname Commands | You should know…

Each of the commands is explained in required detail for better understanding.

1. What is the command to find hostname in Linux?

Use the hostname command without any option.

hostname

It is also called as the domain name of the system.

2. What is the Linux command to get the IP address from hostname without ifconfig?

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 -i and -I option.

hostname -i

Or, you can use…

hostname -I

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.

3. How to get the DNS name of the system?

Use -d option to get the DNS name of the system.

hostname -d

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).

4. How to get the FQDN of the system?

Use -f option with hostname command.

hostname -f

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 -A.

hostname -A

5. How to get the alias name of the host?

There can be an aliased name for your hostname. Use -a flag with hostname command.

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.

I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.