Узнать имя компьютера линукс

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.

Читайте также:  Folders in linux root

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.

Источник

3 способа узнать имя хоста (компьютера) с помощью терминала Linux

Так же как адрес интернет-протокола или IP-адрес дает идентификацию вашему устройству, точно так же имя хоста является еще одним параметром, по которому можно узнать ваше устройство. Оно представляет собой строку символов, понятных человеку. В отличие от IP-адреса, имя хоста ПК легко запомнить и вспомнить. Для этого необходимо всегда знать имя хоста своего компьютера. В этой статье мы расскажем вам, как узнать имя хоста вашего ПК с помощью терминала Linux.

Читайте также:  407 proxy authentication required linux

Поиск имени хоста компьютера в Linux

Чтобы найти имя хоста вашего ПК в Linux, вы можете выполнить любой из трех перечисленных ниже методов:

Метод № 1: Используйте команду hostname

Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав enter. Открывшееся окно терминала показано ниже:

Командная строка терминала

Теперь введите в терминале команду hostname и нажмите клавишу Enter.

Введите команду hostname

Как только вы нажмете клавишу Enter, имя хоста вашего компьютера появится в терминале. Это показано на рисунке ниже:

Имя хоста, отображаемое в оболочке системы Linux

Способ № 2: Используйте команду hostnamectl

Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав enter.

в терминале и нажмите Enter.

Введите команду: hostnamectl

Как только вы нажмете клавишу Enter, в окне терминала появится имя хоста вашего компьютера. Это показано ниже:

Отображается подробная информация о системе Linux, включая имя хоста.

Способ № 3: Используйте команду cat

Запустите терминал, нажав Ctrl +T или щелкнув по значку терминала на панели задач, или найдите терминал, набрав terminal в окне поиска и нажав Enter.

cat /proc/sys/kernel/hostname

в терминале и нажмите клавишу Enter.

Показать содержимое /proc/sys/kernel/hostname

Как только вы нажмете клавишу Enter, на терминале отобразится имя хоста вашего компьютера.

Заключение

Перечисленные выше три метода действительно очень просты и легки. Теперь вы можете найти имя хоста вашего компьютера за несколько секунд и без каких-либо проблем. Надеюсь, эти методы помогут вам.

Похожие записи:

Источник

Hostname Command in Linux – 12 Examples with All Options

A hostname is a name that is given to a computer and used to identify the computer in a network. In this tutorial, we learn about hostname command in Linux with practical examples.

Prerequisites

  • A Linux machine.
  • Access to the terminal.
  • Basic knowledge of using Linux command line.

Hostname Command

The hostname command is commonly used to display Linux computer name or its DNS domain name. You can use it to set a hostname for the computer. This only set the hostname temporarily until the next reboot.

Historically /etc/hostname file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname. /etc/hosts Usually, this is where one sets the domain name by aliasing the host name to the FQDN.

The basic syntax for the Linux hostname command:

hostname [options] [File] [new_hostname]

Hostname command options

Some of the useful options for Linux hostname command.

Options Description
-a Displays alias names of the host system.
-A enumerates all configured network addresses on all configured network interfaces, and translates them to DNS domain names. (fqdn fully qualified domain)
-b set default hostname if none is available
-d Display DNS domain name.
-f Displays long hostname (FQDN). A FQDN consists of a short host name and the DNS domain name
-F read hostname or NIS domain name from the given file
-i Displays all configured addresses for the hostname
-I establishes all configured network interfaces and displays all addresses for the host
-s Displays short hostname.
-V Print version information on standard output and exit successfully
-y Displays the Network Information System NIS/YP domain name
Читайте также:  Wav to flac linux

Hostname Command Examples

The following examples will show how you can use the hostname command with the options.

1. Display Linux Hostname

To display hostname for your Linux machine, the following program displays it:

hostname command displays computer hostname host1.example.com

2. Display IP address

Situations for needing your Linux machine IP address might arise, to display your IP, use the following command:

Using hostname command show ip

And if you need to see all your IP addresses for the machine, use the following command:

Alternatively use ip addr command which gives more information for all addresses.

3. Display DNS domain name

For displaying your current host DNS domain name, the following hostname command gets the job done:

hostname command dns

In this case, the machine didn’t return any value because a local domain is not set

And if it’s the NIS domain name you would like to see, use the following command:

hostname command showing Network Information Services (NIS)

The NIS also returned an error value because a local domain name is not set.

4. Display short hostname

To display your Linux machine short hostname, use the following command:

command short hostname

5. Display all Fully Qualified Domain Names (FQDNs)

To display all your Linux machine FQDNs, the following command will achieve that:

Nevertheless, if you want to only display the machine FQDN, use the following command:

hostname command shows fqdn

6. Change Linux hostname

Maybe you already have a hostname set for your linux machine, but you wish to change it to a new hostname, the following command can be used:

sudo hostname new-hostname

hostname change hostname temporarily

Only the super-user can change a hostname, which explains the “sudo” command appended to the hostname command. Remember changing hostname using hostname will only keep it temporary.

7. Set a default hostname

To set a default system hostname (default hostname localhost) for your linux machine if you don’t have any, the following hostname command will get the job done:

The machine returned a hostname because a hostname has been set.

If you need your machine to read a hostname or a NIS domain name from a specified file, use the following command:

8. Display Linux alias name

If an alias name is set for your Linux machine, the following hostname command will display it:

Command returns a blank line, which means no alias name is set for this system.

9. Hostname help

If you need help understanding more about the hostname command, you can use the help command to figure it out. To use the help command, type the following:

hostname help page

Conclusion

In this tutorial, we learned about Linux hostname command and its options.

Thanks for reading please leave your feedback and suggestions in the comment section.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Источник

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