My LAN has 50 Windows hosts. At the Windows command line I try ping to get the IP address of a running Windows machine.

The question is how to get hostname of a specific IP address in the same Windows workgroup?

Another question is how to know the hostname of Windows machine from a Linux box if I have an IP address? Which command do you use? I have one host running Kubuntu 9.04.

link|improve this question

52% accept rate
feedback

5 Answers

up vote 16 down vote accepted

If you want to determine the name of a windows-machine without dns, you should try NBTSTAT.
But that will only work on Windows:

for e.g. NBTSTAT -A 10.10.10.10

On Linux you should try nmblookup that does nearly the same.

Best regards.

link|improve this answer
1  
NBTSTAT does rely on having NetBIOS loaded and running, which is often switched off in larger organisations with their own AD & DNS infrastructure. Probably a safe assumption here though with a 50 machine workgroup. – GAThrawn Nov 25 '09 at 11:58
Thanks you Decca, the nbtstat is rock btw ... I failed on Linux box nmblookup 192.168.1.92 querying 192.168.1.92 on 192.168.1.255 name_query failed to find name 192.168.1.92 – billyduc Nov 30 '09 at 1:26
3  
The command nmblookup -A 192.168.1.92 is working sucessfully – billyduc Nov 30 '09 at 1:40
Did anyone know the different program to produce the 2D image of the entire network like lanmap? thanks for any suggestion – billyduc Nov 30 '09 at 1:42
SWEEEEEEEEEEEEEEEEEEEEET! Thanks! – RSolberg Feb 18 '10 at 16:18
feedback

The technically preferable method is to type nslookup <ip address>

NSLOOKUP actually asks the DNS server for the IP address of the hostname. Ping will use the local DNS Resolver Cache, which may be incorrect until you flush.

link|improve this answer
that's assuming he has an internal dns server for name resolution. also, the op stated that he wanted to resolve a host name from the ip, so i'm assuming he doesn't know the host name to begin with. also, as far as i'm concerned there's no correct or incorrect way of doing it. there are multiple methods, each of which are valid, and each of which may produce different results. – joeqwerty Nov 25 '09 at 4:58
Nope. Using PING is not the best way of doing it. You can do an nslookup <ip address> and it will resolve the reverse lookup. – Izzy Nov 25 '09 at 5:00
i didn't say ping was the best way, i said it was a way. using nslookup assumes that he has an internal dns infrastructure in place. i didn't make that assumption as he mentioned workgroup in his post. – joeqwerty Nov 25 '09 at 5:03
You refer to NSLOOKUP like it's some internal resolution tool... Either way, NSLOOKUP is the technically superior option. – Izzy Nov 25 '09 at 5:07
But he is correct. nslookup is only of use in this scenario if there is a DNS server (whether that be internal or external) which has reverse lookup zone entries for the OP's hosts, and the OP's machines are configured to use that DNS server. – mh. Nov 25 '09 at 9:52
show 1 more comment
feedback

There couple of ways of doing it in both windows and linux e.g.

1) nslookup : classic way to find ip form hostname or vice-versa.
2) ipconfig or ifconfig based on whether you are running on windows or unix
3) hostname -i in linux

Ref: Multiple ways to get IP address from hostname in linux and windows

link|improve this answer
feedback

in windows you can use ping -a x.x.x.x to attempt to resolve the hostname from the ip address.

link|improve this answer
PING can result in inaccurate results, especially if you're actively working on DNS issues. – Izzy Nov 25 '09 at 4:56
the op didn't state he was working on dns issues, he he implied that he was working on name resolution issues. dns is not the only name resolution mechanism in windows and is not a required name resolution mechanism. he also stated he's working in a workgroup setting so i didn't make any assumption regarding his having a dns infrastructure in place. – joeqwerty Nov 25 '09 at 5:01
DNS is actually required for Active Directory. We simply don't have enough info to say anything definitive regarding that. – mh. Nov 25 '09 at 11:10
@mh: yes it is, but again... not enough info from the op. – joeqwerty Nov 25 '09 at 12:26
thank you all ! I don't have Active Directory service, I have one DNS server resolve for dhcp, mail, web server in my company, most of the employee host are running windows XP and using the same WORKGROUP. – billyduc Nov 30 '09 at 1:33
feedback

nmblookup might not work well for linux hosts. Because Netbios name is deprecated. And in windows, it is limited to local network.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.