Узнать hostname по ip linux

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.

Читайте также:  Save and close file linux

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 to get the NetBIOS name from just the IP. This works across subnets and there’s no need to be in the same domain. Also, running nbtstat -a will do the reverse. Hope this helps.

Источник

Find Hostname from IP Linux

Names or labels are useful as they allow us to identify one thing or one person from another. Even a person’s name, which might not be globally unique, contains a set of characters that allow a person to become distinguished from another person.

Similarly, computers support labels or names that help give them a unique identity in a network. That is where a hostname comes in. A hostname is a set of alphanumerical characters unique to a computer network, allowing devices to communicate with each other.

Читайте также:  Linux home path user

Typically, the underlying technology that identifies a computer or a device in a network is a set of numbers known as IP addresses. These are then mapped to a specific name resolved to the IP address of the machine.

In this tutorial, however, I will show you various ways that you can use to get the hostname associated with a specific IP address. The methods discussed in this tutorial will work in almost all Linux and Unix-Like systems.

If you are looking for detailed instructions on how systems such as Domain Names work, check out the resource on the link provided below:

With that out of the way, let us dive in.

Method 1: Ping

The simplest method to get the hostname from an IP address is to use ping. Ping is a simple yet powerful command-line utility that uses ECHO packets to communicate with a host.

NOTE: The following command only works in Windows machines. For Linux, check the next method.

To get a hostname from an IP address with ping, use the command below:

Here is the output from the above command:

The above command is not always reliable; it often only works if the hostname is available in the hosts file.

Method 2: Host Command

The second and common method for getting the hostname from the IP address in Linux is the host command. This simple tool is part of the dnsutil package.

To install the package, use the commands:

Ubuntu/Debian-based distros

Источник

Найти hostname из IP Linux

Найти hostname из IP Linux

Советы и хитрости

Имена или ярлыки полезны, поскольку они позволяют нам отличить одну вещь или одного человека от другого. Даже имя человека, которое может не быть уникальным в глобальном масштабе, содержит набор символов, которые позволяют человеку отличаться от другого человека.

Точно так же компьютеры поддерживают метки или имена, которые помогают придать им уникальную идентичность в сети. Вот здесь и появляется имя хоста. Имя хоста — это набор буквенно-цифровых символов, уникальных для компьютерной сети, позволяющий устройствам связываться друг с другом.

Как правило, базовая технология, которая идентифицирует компьютер или устройство в сети, представляет собой набор чисел, известных как IP-адреса. Затем они сопоставляются с определенным именем, преобразованным в IP-адрес машины.

Однако в этом руководстве я покажу вам различные способы, которые вы можете использовать для получения имени хоста, связанного с определенным IP-адресом. Методы, обсуждаемые в этом руководстве, будут работать почти во всех Linux и Unix-подобных системах.

Разобравшись с этим, давайте погрузимся.

Метод 1: Ping

Самый простой способ получить имя хоста с IP-адреса — использовать команду ping. Ping — это простая, но мощная утилита командной строки, которая использует пакеты ECHO для связи с хостом.

ПРИМЕЧАНИЕ. Следующая команда работает только на компьютерах с Windows. Для Linux проверьте следующий метод.

Чтобы получить имя хоста с IP-адреса с помощью команды ping, используйте команду ниже:

Читайте также:  Переключить язык кали линукс

Вот результат выполнения вышеуказанной команды:

Вот результат выполнения вышеуказанной команды

Приведенная выше команда не всегда надежна; это часто работает только в том случае, если имя хоста доступно в файле hosts.

Метод 2: команда хоста

Второй и распространенный метод получения имени хоста из IP-адреса в Linux — это команда host. Этот простой инструмент является частью пакета dnsutil.

Для установки пакета используйте команды:

Дистрибутивы на основе Ubuntu / Debian

Источник

How to get a hostname/domain name from an IP address in Linux

One of the questions that many Linux users ask is how they can retrieve a system’s hostname using its IP address. It may seem an uphill task, but in the real sense, it’s quite easy. Essentially, this is known as the reverse DNS lookup. Reverse DNS lookup queries an IP address to retrieve the hostname or domain of the server. The exact opposite is the Forward DNS lookup which maps the domain name to the IP address.

In this short guide, we have explored a few ways to performs Reverse DNS lookup and get a domain name from an IP address. For demonstration purposes, I have used Ubuntu 20.04.

Prerequisites

Before you roll up your sleeves, ensure that your remote host has an A record which is a DNS entry that points or maps a domain name to an IP address

Perform DNS Reverse lookup using dig command

Dig command is a flexible and powerful tool that is used for querying or probing DNS records. It’s an acronym for domain information groper and allows you to retrieve a wide array of DNS information such as A, CNAME, MX, and SOA records.

Perform DNS Reverse lookup using nslookup command

A nslookup command is a troubleshooting tool that features highly in a sysadmin’s armory. It’s a versatile tool that performs all DNS record querying such as CNAME, A, MX, and reverses or PTR records.

To retrieve a domain name from an IP address, use the command syntax:

Perform DNS Reverse lookup using the host command

Similarly, you can use the host command to obtain a hostname or domain name from an IP address using the syntax as shown.

For example, to check the domain name for the IP 5.9.235.235, execute the command:

Just like the Nslookup command, you can also use the host command with hostnames or IP addresses.

Conclusion

The few examples that we have just elaborated are a sure way of helping you obtain the domain name from an IP address. Usually, the reverse DNS lookup is trivial and not as crucial as the forward lookup, which maps domain names to IP addresses. Your feedback or contribution will be highly welcomed.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

Источник

Оцените статью
Adblock
detector