How to Find Hostname From IP Linux?

In Linux, the hostname is given to the computer for unique identification over the network. In simple words, the hostname is a combination of alphanumeric characters that enable the system to communicate. There are 3 ways to find out the hostname in Linux.

This post will demonstrate methods to find the hostname from IP Linux. The content for the post is as follows:

Let’s start with the first method.

Method 1: Using the host Command

To find the hostname in Linux, you can use the hostname utility in the terminal with the IP address of the Linux operating system as we did here following the command.

$ host 172.17.0.1

The hostname “ubuntu” is printed on the screen.

Method 2: Using the dig Command

Another method to search the hostname in Linux is the “dig” utility. The “dig” stands for domain information groper used to obtain the DNS information. This command can be used with the “x” option and IP address for displaying the hostname:

$ dig -x 172.17.0.1

The hostname “ubuntu” is printed on the screen, as shown above.

Let’s move toward method 3.

Method 3: Using the nslookup Command

The third method used for searching the hostname is the “nslookup” command. The nslookup enables you to consult your DNS queries. Use the “nslookup” command with the IP address of your system:

$ nslookup 172.17.0.1

The hostname will be printed on the screen.

Bonus Tip: How to Set the Hostname in Linux?

To set the hostname in Linux, run the given command in the terminal:

$ nmtui

Once you run the command above, the following interface will be opened. Use the tab key and press enter on the “set system hostname” option:

Type the desired hostname, and navigate to the “OK” button using the tab key:

Setting the new hostname will ask for user authentication, authenticate it by entering your system password:

After authenticating, the hostname will be changed.

That’s how you can find the hostname.

Conclusion

To find the hostname from IP, three methods are available “hostname”, “dig”, or “nslookup” utility with the IP address of your system. This write-up has illustrated all the possible methods for finding the hostname from the IP address. Additionally, the method for setting the hostname has also been illustrated in this article.