How to get hostname from IP (Linux)?

给你一囗甜甜゛ 提交于 2020-07-04 05:54:07

问题


I'd like to get remote machine/hostname through IP Address. I found lots of answer such as nslookup, host, resloveip, etc.. but I still can't get hostname from my target machine(cent OS, ubuntu etc...) It seems need to register to DNS server?

I have a machine named test and using IP 10.1.27.97

but I used the method above still can't not get "test"

Does anyone can help me to get the hostname form IP Address?


回答1:


In order to use nslookup, host or gethostbyname() then the target's name will need to be registered with DNS or statically defined in the hosts file on the machine running your program. Yes, you could connect to the target with SSH or some other application and query it directly, but for a generic solution you'll need some sort of DNS entry for it.




回答2:


To find a hostname in your local network by IP address you can use:

nmblookup -A <ip>

To find a hostname on the internet you could use the host program:

host <ip>

Or you can install nbtscan by running:

sudo apt-get install nbtscan

And use:

nbtscan <ip>

*Taken from https://askubuntu.com/questions/205063/command-to-get-the-hostname-of-remote-server-using-ip-address/205067#205067

Update 2018-05-13

You can query a name server with nslookup. It works both ways!

nslookup <IP>
nslookup <hostname>


来源:https://stackoverflow.com/questions/24182950/how-to-get-hostname-from-ip-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!