7 Linux Hostname Commands with Example | You should Know

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.

Table of Content:

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.


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.

hostname -a

Additional read: Linux Command to check the Serial Number


6. What is the Linux command to change hostname?

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.

7. How to make the hostname changes permanent?

There is a way to make the changes permanent if you wish.

Use a command hostnamectl.


Before you leave…

You can explore and find more hostname commands using help option.

Hostname help command:

There are many other options you can use with hostname. You can get all the options by running a command hostname -h.

hostname -h

All the above-mentioned commands are tested on Ubuntu system and will work with any other Linux distribution.

Related Article:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *