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

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.

Читайте также:  The best linux books

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.

Источник

How to Use the hostname Command in Linux

The Linux hostname command is used to view or change a system’s domain and hostname. It can also check a computer’s IP address.

In this tutorial, we will cover all the ways you can use the hostname command on Linux and how to change your computer’s hostname on a Linux system.

How to use the Linux hostname command

hostname Command Syntax

The hostname command uses the following format:

hostname [options] [new_hostname]

Use the [options] parameter to add more specific instructions to the hostname command. Without it, the default output shows your computer’s hostname:

Читайте также:  Add interface network linux

Use the [new_hostname] parameter when you want to change your computer’s hostname.

hostname Command Examples

The hostname command has a number of options you can use for more specific outputs:

  • -a , —alias : Displays the alias name of the host.
  • -A , —all-fqdns : Displays every FQDN (Fully Qualified Domain Name) of the computer.
  • -b , —boot : Always set a hostname.
  • -d , —domain : Display DNS domain name.
  • -f , —fqdn , —long : Display the FQDN.
  • -F , —file : Check a file to recover and display the hostname.
  • -h , —help : Print the help message as the output.
  • -i , —ip-address : Display the computer’s IP address.
  • -I , —all-ip-addresses : Display all of the computer’s network addresses.
  • -s , —short : Display the short version of the hostname.
  • -v , —verbose : Expand all output to verbose.
  • -y , —yp , —nis : Display the NIS domain name.

Display Hostname

Using the hostname command without any additional options displays the computer’s hostname:

Display hostname

Display Short Hostname

Use the -s or —short option to display the short version of the hostname, which is cut off at the first dot:

hostname -s hostname --short

Display short hostname

Display Alias

Use the -a or —alias option to display the alias (substitute hostname) of the host if one is set. There are very few cases where this option is useful, and its use is no longer recommended.

hostname -a hostname --alias

Display alias

Search for Hostnames

Use the -F or —file option to search a specific file (such as hostname or hosts) and change your computer’s hostname to match the content of the file:

sudo hostname -F [file path] sudo hostname --file [file path]

Search for hostnames

Note: When using the -F or —file options, also specify the path to the file you want to check.

Force Default Hostname

If you don’t want to have a specific file containing the hostname, or want to leave that file empty, use the -b or —boot option. This makes your computer use the default hostname (localhost) until you set a different one:

Force default hostname

Display Domain Name

Use the -d or —domain option to display the name of your DNS domain:

hostname -d hostname –domain

Display FQDN

If you want to display a system’s FQDN, use the -f , —fqdn , or —long option:

hostname -f hostname --fqdn hostname --long

A FQDN contains the short hostname and the DNS domain name.

Display All FQDNs

To display each FQDN of your machine, use the -A or —all-fqdns option:

hostname -A hostname --all-fqdns

This option lists out all of your network addresses and their DNS domain names. It skips any addresses that it can’t translate.

Note: Different network addresses may translate to same DNS domain names. This can result in duplicate output entries when using -A or —all-fqdns options.

Display NIS Domain

If you’re using NIS (Network Information Service), you can check your NIS domain name with the -y , —yp , or —nis option:

hostname -y hostname --yp hostname --nis

Display NIS domain

Change NIS Domain Name

Use this command with the following format to change your NIS domain name:

sudo hostname -y [NIS hostname] sudo hostname --yp [NIS hostname] sudo hostname --nis [NIS hostname]

Change NIS domain name

The hostname command also lets your display network addresses tied to a hostname. To do this, use the -i or —ip-address option:

hostname -i hostname --ip-address

This command only works if the hostname can be resolved.

Читайте также:  Astra linux установочный образ

Display related network addresses

Display All Network Addresses

Use the -I or —all-ip-addresses option to display all of the host’s network addresses. Unlike -i , this option doesn’t depend on hostname resolution:

hostname -I hostname --all-ip-addresses

Display all network addresses

Change Hostname Until Reboot

You can change your computer’s hostname with the hostname command. To do this, use the following format:

sudo hostname [new hostname]

Any changes to the hostname you make using this command will only last until the next reboot.

Change hostname until reboot

Change Hostname Permanently

To change the hostname permanently, use a text editor like Nano to make changes to the hostname and hosts files:

sudo nano /etc/hostname sudo nano /etc/hosts

You can also use the hostnamectl command to permanently change the hostname:

sudo hostnamectl set-hostname [new hostname]

Change hostname permanently

Additional hostname Options

Use the -V or —version option to print out the version of the hostname software package on your Linux system:

hostname -V hostname --version

Display hostname version

If you need help with any of the commands, use the -h or —help option to print out a help message:

Hostname help output

After following this guide, you now know how to use the hostname command in Linux and all the options that can extend its use.

For more Linux commands, check out our Linux Commands Cheat Sheet.

Источник

Как изменить Hostname (имя компьютера)

Как изменить Hostname

Hostname (имя компьютера, имя хоста) задается во время установки системы Linux. Hostname определяет название компьютера и используется преимущественно для идентификации компьютера в сети. Нельзя назначать два одинаковых Hostname для компьютеров в одной сети.

Просмотр текущего Hostname

Чтобы показать текущий Hostname можно использовать команду hostname без параметров:

Также Hostname можно отобразить командой hostnamectl :

Как изменить Hostname

Рассмотрим, как изменить Hostname двумя разными способами.

Способ 1. Используем команду hostnamectl

Во многих systemd-based дистрибутивах (например, в Ubuntu Linux) есть утилита hostnamectl .

Воспользуемся командой hostnamectl , чтобы установить новое значение Hostname равным pingvinus . Используется аргумент set-hostname:

sudo hostnamectl set-hostname pingvinus

Способ 2. Редактируем файлы /etc/hostname и /etc/hosts

Еще один способ изменения Hostname — это ручное редактирование файла /etc/hostname и файла /etc/hosts .

Сначала выполните команду (вместо pingvinus укажите свое значение):

Отредактируем файл /etc/hostname для редактирования в редакторе nano, выполняем команду:

Измените текущее значение в файле на новое. Сохраните изменения и закройте файл. Это можно сделать, нажав Ctrl+C , затем Y и Enter .

Hostname прописывается также в файле /etc/hosts , поэтому нужно изменить его значение в этом файле. Откроем файл:

Найдите строку вида « 127.0.0.1 ваш_hostname » и впишите новое имя хоста. Сохраните изменения и закройте файл.

Проверка результата

Чтобы проверить, изменилось ли значение Hostname, откройте новое окно терминала и введите команду:

Как временно изменить Hostname

Чтобы изменить Hostname в текущей работающей системе Linux, но до первой перезагрузки, можно использовать просто команду hostname , указав ей новое значение имени хоста:

Источник

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