How to Get a Hostname/Domain Name From an IP Address in Linux?

The hostname is the unique name assigned to a system or device on a network, while it is also called the “domain” name. It is beneficial to connect many systems to the network compared to the IP address as it is difficult for users to remember the IP address of each system. If the user knows the IP address of a system, then it can easily get its host/domain name associated with it.

This post offers multiple ways to get the hostname/domain name from an IP address in Linux. The outcomes of this post are listed below:

Let’s start with the first method.

Method 1: Using the “nslookup” Command

The “nslookup” stands for (Network Server Lookup). It is a network command line tool to query the DNS(Domain name Server), and obtain the domain name, IP address, or any other DNS record.

In this method, the “nslookup” command is utilized to get the hostname/domain name from the particular address. To perform this task, type the “nslookup” command in the terminal with the specific IP address:

$ nslookup <IP-Address>

In the above output, “ubuntu” is the hostname, whereas the “.local” is the network (or the domain name) through which the “ubuntu” is available and can be accessed by other users on the local network.

Note: The IP address used in this post is “1922.168.59.132”.

Method 2: Using the “host” Command

This is another command line utility helpful for DNS server lookup. It is generally used to find the DNS server information, such as the domain name from its associated IP address or the IP address from the domain name.

In this scenario, the desired system IP address is mentioned with the “host” command to get the associated hostname/domain name:

$ host <IP-Address>

 The “host” command output displays the hostname “ubuntu” and the domain name “ubuntu.local” associated with the IP address “

Method 3: Using the “dig” Command

The “dig” command is the network tool with a basic command line interface. This command line utility is used for making different DNS queries. The “dig” is beneficial for diagnosing the server names, checking all available DNS records, and much more.

Here in this method, it is used with its various flags to get the hostname/domain name from an IP address.

To Get the Detailed Information

The “-x” flag of the “dig” command specifies the hostname/domain name in the query “ANSWER SECTION” associated with the given IP address:

$ dig -x <IP-Address>

The current Linux distro hostname is “ubuntu”, and domain name is “ubuntu.local” from the “” Ip address.

To Get the Short Information

Apart from that, use the “+short” flag with the “dig” command to get only the hostname from the IP address in the following way:

$ dig -x <IP-Address> +short

The “+short” displays the hostname “ubuntu” and the “ubuntu.local” domain name without the “IP” address.

To Get The Specific Section From the Output

The “dig” command also provides the “+noall” option to exclude all the results except the one mentioned in the command. In this case, the “+noall” disables all the sections except the “answer” section:

$ dig -x <IP-Address> +noall +answer

The hostname “ubuntu” and the domain name “ubuntu.local” is successfully displayed in the output.

It’s all about getting the hostname/domain name from the particular IP address in Linux.


Linux offers the well-reputed “nslookup” and “host” command line utilities to get the hostname or domain name from the specified IP address. In addition, the “dig” command is also beneficial for performing this task. This post has briefly illustrated all the possible ways to get the hostname/domain name from the IP address.