91

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.

billyduc
  • 1,617
  • 8
  • 24
  • 26

6 Answers6

97

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.

Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
Phil Swiss
  • 1,437
  • 9
  • 4
  • 3
    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 01:26
  • 8
    The command nmblookup -A 192.168.1.92 is working sucessfully – billyduc Nov 30 '09 at 01:40
  • 1
    `nmblookup` is part of my distro's Samba package. Not sure why `nmblookup` that does ip to hostname is part of Samba (networked file system code and print services code). – Trevor Boyd Smith Feb 28 '17 at 18:12
68

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.

Izzy
  • 8,224
  • 2
  • 31
  • 35
  • 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 04:58
  • 3
    Nope. Using PING is not the best way of doing it. You can do an `nslookup ` and it will resolve the reverse lookup. – Izzy Nov 25 '09 at 05: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 05: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 05:07
  • 1
    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. – Maximus Minimus Nov 25 '09 at 09:52
  • @mh& @izzy: i'm not debating that nslookup is not the proper tool to use. nslookup is the tool i would use in my environment where i know i have dns set up. i would use it for testing external dns resolution also, but as the op didn't give us enough detail, my answer was based on what was likely to give him some kind of result. maybe he'll post back with more info. – joeqwerty Nov 25 '09 at 12:30
  • 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 03:09
12

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

Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
joeqwerty
  • 109,901
  • 6
  • 81
  • 172
  • 1
    PING can result in inaccurate results, especially if you're actively working on DNS issues. – Izzy Nov 25 '09 at 04: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 05:01
  • DNS is actually required for Active Directory. We simply don't have enough info to say anything definitive regarding that. – Maximus Minimus 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 01:33
  • @joeqwerty Nice gravitar. Seriously. – styfle Nov 21 '13 at 02:44
  • LOL. Homestar Runner. – joeqwerty Nov 21 '13 at 04:00
  • @Izzy, What do you mean by "PING can result in inaccurate results, especially if you're actively working on DNS issues"? – Pacerier Jan 25 '15 at 18:23
6

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

Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
Sreedhar
  • 61
  • 1
  • 1
5

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.

balupton
  • 186
  • 1
  • 6
1

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

Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
Arun
  • 11
  • 1
  • 3
    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 06: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 04 '13 at 14:47
  • Sadly, yes: https://serverfault.com/questions/676867/error-adding-child-active-directory-domain-to-existing-forest – Massimo Feb 13 '19 at 22:55