How to find a computer name in a LAN from the IP address?

Solution 1:

Type in terminal.

sudo nmap -sn <Your LAN Subnet>

For Example:

sudo nmap -sn 192.168.1.*

You can find your LAN subnet using ip addr command.

It will show all host name in LAN whether it is Linux or Windows. You also able to see mobile devices, if any present on LAN network. Here you need to make sure that you run command with sudo or root.

Solution 2:

Type in terminal

sudo aptitude install nmap
nmap -sP xxx.xxx.xxx.xxx

This will give you:

Starting Nmap 5.21 ( http://nmap.org ) at 2012-11-03 19:08 CET
Nmap scan report for HOST.DOMAIN (xxx.xxx.xxx.xxx)
Host is up (0.00052s latency).
MAC Address: YY:YY:YY:YY:YY:YY (Manufactor)
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

Where HOST.DOMAIN is the DNS-name of the machine.

Solution 3:

A Netbios name reverse lookup might accomplish what you want more than than "hostname" which is a function of DNS and tcp/ip. nmblookup with the -A parameter returns device names as well as mac address. Try something like this:

nmblookup -A 192.168.1.2