Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

6 Answers 6

up vote 69 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 example,

NBTSTAT -A 10.10.10.10

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

share|improve this answer
2  
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
6  
The command nmblookup -A 192.168.1.92 is working sucessfully –  billyduc Nov 30 '09 at 1:40

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.

share|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
3  
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
1  
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
3  
@Izzy I registered as a new member just to say thanks for the tip for NSLOOKUP, Izzy. Out of all the stuff above, it's the only one that worked for me. Thanks a million. --Jeff Moden –  Jeff Moden Jul 18 '12 at 3:09

On Windows you can use ping -a x.x.x.x to attempt to resolve the hostname from the IP address.

share|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. –  Darth Satan 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

There are a couple of ways of doing it on both Windows and Linux. For example,

  1. nslookup: the classic way to find the IP address from a hostname or vice-versa.
  2. ipconfig or ifconfig based on whether you are running on Windows or Unix
  3. hostname -i on Linux

Ref: Multiple ways to get IP address from hostname in Linux and Windows

share|improve this answer

For mac users smbutil -v status -ae x.x.x.x works. You can also use arp -a to get mac addresses for everything on your network.

share|improve this answer

nmblookup might not work well for Linux hosts, because the NetBIOS name is deprecated. And on Windows, it is limited to the local network.

share|improve this answer
2  
No, that's wrong. Netbios is (sadly) not deprecated, and actually required for a number of vital Active Directory functions. –  HopelessN00b Nov 22 '12 at 6:20
    
Can somebody point out how in which cases AD DS still relies on Netbios? There have been talks that Netbios bound to be depricate since Windows Server 2003 times. Does it still somehow required now with Windows Server 2012 AD DS networks? –  Mikhail Dec 4 '13 at 14:47

protected by Tom O'Connor Aug 22 '13 at 19:39

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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