How to get the hostname using terminal command-line?

Solution 1:

Assuming you have a local DNS server set up, dig should do

dig +short -x 123.456.789.12

(Yes, that's not a valid IP, it's a Hollywood IP)

Solution 2:

try nslookup

Note: All tools require a DNS that have a reverse lookup zone. (the default is forward lookup zone only). This is why it will work on most external domains (internet) because they are registered in DNS all over the internet. for internal network you need an internal DNS reverse lookup server. check the following link

Solution 3:

To get the hostname from the IP address. The simplest way is to use the “host” utility . Just run…

# host 64.233.187.99
output is: #99.187.233.64.in-addr.arpa domain name pointer jc-in-f99.google.com.

This will query the name server and provide you with the hostname of the IP address.By default it will query the nameserver listed in the /etc/resolv.conf file.