- How to find a computer name in a LAN from the IP address?
- 7 Answers 7
- 3 способа узнать имя хоста (компьютера) с помощью терминала Linux
- Поиск имени хоста компьютера в Linux
- Метод № 1: Используйте команду hostname
- Способ № 2: Используйте команду hostnamectl
- Способ № 3: Используйте команду cat
- Заключение
- Похожие записи:
- Get the Hostname From an IP Address in Linux
- 1. Overview
- 2. Get the Hostname from a Public IP Address
- 2.1. Using the Command host
- 2.2. Using the Command dig
- 3. Get the Hostname From an IP Address on the LAN
- 3.1. Using the Command nmblookup
- 3.2. Using the Command nbtscan
- 3.3. Using the Command avahi-resolve
- 4. Conclusion
How to find a computer name in a LAN from the IP address?
My network includes machines running Linux and others running Windows. And my machine is running Linux.
The question is a bit unclear, which resulted in the varying — and good — answers below. Do you want to find the DNS name of a host? Do you want to find the WINS name? Do you want to search the network for all hosts found? All of these questions are answered — but the specific answer desired is unknown.
7 Answers 7
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.
On Ubuntu 14.04 this says: «? (192.168.1.2) at 00:22:6b:f2:33:b3 [ether] on wlan0», giving me only info about my router (my laptop is connected to it via wifi, like about other 10 devices atm). Looking at man arp it says also «arp — manipulate the system ARP cache». How should this tool solve the original question?
Same here on Ubuntu 14.04, this just lists a bunch of ? (192.168.55.147) at ac:3a:7a:a4:01:d4 [ether] on eth0
Same here. I can only access the localhost by hostname, nothing else seems to advertise it’s hostname, even linux machines I have set up myself.
sudo aptitude install nmap nmap -sP xxx.xxx.xxx.xxx
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.
This shows all active IPs, but it only shows domains for machines which explicitly have custom domain configured in my local Bind server. It doesn’t show any local hostnames, which I think is what the OP is trying to accomplish.
-sP may have been changed to -sn depending on your version of nmap. From the nmap 7.12 manual: -sn (No port scan) In previous releases of Nmap, -sn was known as -sP.
Similar to the arp command, I believe this answer only works if you have a local DHCP server and DNS server/proxy that communicate with one another, so that the hostnames recorded with the DHCP leases can be resolved (or reverse-resolved, in this case) via DNS.
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:
You can run it in windows
nbtstat -A xxx.xxx.xxx.xxx (where x is the ip address)
on ubuntu you can install nbtscan. You can find more information here : http://www.unixwiz.net/tools/nbtscan.html
Thanks very much, but it seems that nbtscan detects machines running Windows only. I’ve 2 machines running Windows and another 2 running Linux. It detects the two running Windows only.
Sorry, I’ve read the tutorial but couldn’t figure out how to write the command that solves my problem. I can’t see options taking IP as input. Can you write the command for me please?
try nmblookup -A xxx.xxx.x.x where x is the ip address of the machine. So I would do nmblookup -A 192.168.1.6 and it would return the name of my machine. You will need to do that for each machine.
@Brett: (+1) you should convert your comment into an answer, as its the only method that worked for me (both windows and linux boxes). Thanks
it will show me the host name (usually the computer name)
nslookup does DNS searches, so for this to work you need the hosts to be registered in the DNS. If you have a regular Windows network, in a private IP range, without ActiveDirectory configured, it will not work. NetBios names, and DNS names are different beasts.
If your network is running a DHCP server, usually on the modem/router, chances are it will have a way for you to see the DHCP assigned addresses — often by a web page, and that often lists the computer names beside the allocated ip addresses.
To the best of my knowledge, there is no utility available to resolve an IP address into a NetBIOS name. I’d imagine that some sort of a network scoping program or a penetration testing program might be able to give you that sore of information though. However, all of the computers would have to be on the same domain and subnet.
I know this is old. and OP is using Linux, not Windows. but on Windows you can run nbtstat -A
3 способа узнать имя хоста (компьютера) с помощью терминала Linux
Так же как адрес интернет-протокола или IP-адрес дает идентификацию вашему устройству, точно так же имя хоста является еще одним параметром, по которому можно узнать ваше устройство. Оно представляет собой строку символов, понятных человеку. В отличие от IP-адреса, имя хоста ПК легко запомнить и вспомнить. Для этого необходимо всегда знать имя хоста своего компьютера. В этой статье мы расскажем вам, как узнать имя хоста вашего ПК с помощью терминала Linux.
Поиск имени хоста компьютера в Linux
Чтобы найти имя хоста вашего ПК в Linux, вы можете выполнить любой из трех перечисленных ниже методов:
Метод № 1: Используйте команду hostname
Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав enter. Открывшееся окно терминала показано ниже:
Теперь введите в терминале команду hostname и нажмите клавишу Enter.
Как только вы нажмете клавишу Enter, имя хоста вашего компьютера появится в терминале. Это показано на рисунке ниже:
Имя хоста, отображаемое в оболочке системы Linux
Способ № 2: Используйте команду hostnamectl
Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав enter.
в терминале и нажмите Enter.
Как только вы нажмете клавишу Enter, в окне терминала появится имя хоста вашего компьютера. Это показано ниже:
Отображается подробная информация о системе Linux, включая имя хоста.
Способ № 3: Используйте команду cat
Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав Enter.
cat /proc/sys/kernel/hostname
в терминале и нажмите клавишу Enter.
Как только вы нажмете клавишу Enter, на терминале отобразится имя хоста вашего компьютера.
Заключение
Перечисленные выше три метода действительно очень просты и легки. Теперь вы можете найти имя хоста вашего компьютера за несколько секунд и без каких-либо проблем. Надеюсь, эти методы помогут вам.
Похожие записи:
Get the Hostname From an IP Address in Linux
The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.
To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.
Connect your cluster and start monitoring your K8s costs right away:
1. Overview
Sometimes we need to get the hostname from an IP address in Linux. This could be a simple action but there are different scenarios to consider. In this tutorial, we’ll take a look at those situations and how to deal with them using some useful commands.
2. Get the Hostname from a Public IP Address
In the case when the host has a public IP address and a valid reverse DNS entry, we can use the commands host or dig.
2.1. Using the Command host
The host command performs DNS lookups to convert names to IP addresses and vice versa.
$ host 8.8.8.8 8.8.8.8.in-addr.arpa domain name pointer dns.google.
In this example, we’ve used the command host to get the hostname for the IP address 8.8.8.8 (The Google DNS).
2.2. Using the Command dig
The dig command is a tool for performing DNS lookups and displays the answers returned from the name server(s) that were queried.
Now, to query for an IP address, we would need to use the option -x:
$ dig -x 8.8.8.8 ; > DiG 9.16.15-Ubuntu > -x 8.8.8.8 ;; global options: +cmd ;; Got answer: ;; ->>HEADER
The default output of the dig command contains more information than the host command. However, dig provides options to customize it. For example:
$ dig -x 8.8.8.8 +noall +answer 8.8.8.8.in-addr.arpa. 68159 IN PTR dns.google.
The first option +noall removes all lines in the output and then we’ve included the answer section with the option +answer.
3. Get the Hostname From an IP Address on the LAN
When we need to get the hostname of a machine on the same LAN and without a reverse DNS, we can use commands like nmblookup, nbtscan or avahi-resolve. The first two commands are used to lookup NetBIOS names. The last one is used to lookup using the Avahi daemon:
- NetBIOS is used by Windows and Linux (with Samba) devices to publish their addresses.
- Avahi is used by macOS, Windows 10+, and Linux (running the avahi-daemon) devices to publish their addresses via Multicast DNS.
3.1. Using the Command nmblookup
The nmblookup command queries NetBIOS names and maps them to IP addresses in a network.
Similar to other commands, we would need to use an option to use an IP address as an argument:
$ nmblookup -A 192.168.1.142 Looking up status of 192.168.1.142 WORKGROUP - B LAPTOP-PQCDJ0QF - B MAC Address = E8-48-B8-8E-CA-4A
As you can see in the previous example, the nmblookup command can display the hostname, workgroup and MAC address of the given IP address.
3.2. Using the Command nbtscan
Contrary to nmblookup, the nbtscan command shows received NetBIOS information in human-readable form.
Let’s try the same IP address:
$ nbtscan 192.168.1.142 Doing NBT name scan for addresses from 192.168.1.142 IP address NetBIOS Name Server User MAC address ------------------------------------------------------------------------------ 192.168.1.142 LAPTOP-PQCDJ0QF e8:48:b8:8e:ca:4a
The nbtscan command returns the output in a “table” format because this is more human-readable and we have the possibility of querying an IP address range as well.
3.3. Using the Command avahi-resolve
The avahi-resolve command resolves one or more mDNS/DNS hostname(s) using the Avahi daemon.
The usage is similar to other commands:
$ avahi-resolve -a 192.168.1.142 192.168.1.142 LAPTOP-PQCDJ0QF.local
In this case, the returned output only shows the IP address and its hostname.
4. Conclusion
In this tutorial, we’ve learned how to get the hostname from an IP address in Linux using different commands like host or dig when the host has a public IP address and a valid reverse DNS entry or commands nmblookup, nbtscan or avahi-resolve when the equipment is on the same LAN. We would have to identify the current scenario to choose the appropriate command or simply try all of them until we get the expected result.