How to Get Hostname from IP Address - unix /linux

The host command in unix or linux operating system can be used to get the hostname from an IP address. An example is shown below:

> host is an alias for 171.128-
171.128- domain name pointer 4-59-125-171-hou.servercraft.co.

The host command gets the hostname listed in the /etc/resolv.conf file by querying the nameserver.

Another way to get the hostname is to user the nslookup command.

> nslookup

Non-authoritative answer:       canonical name = 171.128-
171.128-       name = 4-59-125-171-hou.servercraft.co.

Authoritative answers can be found from:
128-   nameserver = ns1.p23.dynect.net.
128-   nameserver = ns5.p23.dynect.net.
128-   nameserver = ns3.p23.dynect.net.
128-   nameserver = ns2.p23.dynect.net.
128-   nameserver = ns4.p23.dynect.net.
ns4.p23.dynect.net      internet address =
ns3.p23.dynect.net      internet address =
ns1.p23.dynect.net      internet address =
ns2.p23.dynect.net      internet address =

Here the hostname is highlighted in the green color. The alias name for the hostname is highlighted in the red color. If you are connected the remote host, you can get the hostname of the remote machine by using the arp command. It will list all the hostnames with the IP address. Another way is to simply type the hostname command on the remote server to know its host name.

1 comment:

  1. I am using Linux 4. But these two commands are n't working. This is the output of command.

    [papu@localhost ~]$ nslookup

    ** server can't find NXDOMAIN

    [papu@localhost ~]$ host
    Host not found: 3(NXDOMAIN)
    [papu@localhost ~]$

    Piz tell me how to check ?