LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2017, 12:38 PM   #1
unfa
LQ Newbie
 
Registered: Apr 2015
Posts: 2

Rep: Reputation: Disabled
How do I find a machine in the LAN?


Here's a little noob story and an elaborate question.

I've got a LAN network at my workplace with about 30 nodes, two of which I currently operate.

The main machine I use is a desktop, but the second one is headless right now, so I wanted to be able to access it via SSH and VNC to not have to plug my only mouse and keyboard from one to the other all the time.

I managed to get SSH and VNC working, but if I reboot the machine and it gets a different IP address from the router I might now be able to find it.

I tried finding it by hostname, but arp doens't show any hostnames I thought devices advertise their hostnames somehow - maybe I'm wrong?

I was able to use nmap -O to discover Linux machines among the whole bunch, but that scan takes about 75 minutes on that network - not practical to do every time I want to log into SSH.

I've figured out that if I write down the MAC address of my remote machine I will be able to find it's IP:
Code:
arp | grep "ff:ff:ff:ff:ff:ff" | cut -d' ' -f1
That was after I manually checked the IP on the remote headless machine (oh the cables!) and had a working SSH and VNC connections. Haven't I did that - arp would probably not help me find that machine, would it?

I'd like to be able to find that machine on the network easily, that's probably very simple to do, but I can't figure it out.

I've realized that probably only IPs listed in /etc/hosts will be displayed in arp output, and that machines don't tell their hostnames to strangers, even on a local network.

Also - I guess using nmap is a last resort and if it were such a basic tool, it'd be installed on most Linux distributions by default.

I'm running Linux Mint 18.2 on both machines.

Last edited by unfa; 10-27-2017 at 12:40 PM. Reason: Bad formatting.
 
Old 10-27-2017, 12:49 PM   #2
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Why not just give it a fixed IP address in the first place? In my experience even without that most leases are long enough that a simple reboot ought not to change the IP address. What's the layout of the network?
 
Old 10-27-2017, 01:06 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by unfa View Post
Here's a little noob story and an elaborate question.

I've got a LAN network at my workplace with about 30 nodes, two of which I currently operate. The main machine I use is a desktop, but the second one is headless right now, so I wanted to be able to access it via SSH and VNC to not have to plug my only mouse and keyboard from one to the other all the time. I managed to get SSH and VNC working, but if I reboot the machine and it gets a different IP address from the router I might now be able to find it. I tried finding it by hostname, but arp doens't show any hostnames I thought devices advertise their hostnames somehow - maybe I'm wrong?

I was able to use nmap -O to discover Linux machines among the whole bunch, but that scan takes about 75 minutes on that network - not practical to do every time I want to log into SSH. I've figured out that if I write down the MAC address of my remote machine I will be able to find it's IP:
Code:
arp | grep "ff:ff:ff:ff:ff:ff" | cut -d' ' -f1
That was after I manually checked the IP on the remote headless machine (oh the cables!) and had a working SSH and VNC connections. Haven't I did that - arp would probably not help me find that machine, would it? I'd like to be able to find that machine on the network easily, that's probably very simple to do, but I can't figure it out.

I've realized that probably only IPs listed in /etc/hosts will be displayed in arp output, and that machines don't tell their hostnames to strangers, even on a local network. Also - I guess using nmap is a last resort and if it were such a basic tool, it'd be installed on most Linux distributions by default. I'm running Linux Mint 18.2 on both machines.
The first thing I'd suggest would be to give your second machine a static IP address and if you can't do that, see if you can get a DHCP reservation (essentially, a static address that's automatically assigned). Those are the easiest options.

And yes, the arp command will work, try this:
Code:
arp -n | grep -i aa:bb:cc:dd:ee:ff
...instead. Note that if your lease expires, your ARP tables may take a short while to rebuild with the new entry, pointing to the right MAC address.
 
Old 10-27-2017, 09:08 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
I would recommend nmap. Do a web search for "nmap tutorial" or see man nmap

Last edited by frankbell; 10-27-2017 at 09:09 PM.
 
Old 10-28-2017, 10:15 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
nmap can give you the OS, but it does not give you the host name.

A fast tool to discover active IP addresses is fping which gives you all the active IP addresses. After that, the arp cache contains the MAC addresses of pinged machines and you can recognize your MAC address.

But it is still a workaround. Give that machine a fixed IP. Either by adding a reservation in the DHCP server, or assigning a unique address outside the DHCP address pool.

Another option (less known I think) is that virtually every Linux installation now supports IPv6. Since this is your local network you don't relay on external routers. Your host will have a unique, fixed IPv6 link local address.

jlinkels
 
Old 10-28-2017, 02:35 PM   #6
Jackpot
Member
 
Registered: Jul 2016
Location: Bumblefuck
Distribution: Windows7 Windows10 Ubuntu16 KaliRolling
Posts: 60

Rep: Reputation: Disabled
This is the simplest way of performing host discovery is with nmap.

# nmap -sP 192.168.X.X/24



Another option is to install the Fing app on your phone. I love this app and use it on every network I connect to... Once intalled, just connect to your network and perform a discovery. Will show you every machine on that network and has the ability to save info for multiple networks. Just a thought

I would set a static ip down the line though to make shit easier for yourself
 
Old 10-28-2017, 07:38 PM   #7
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by Jackpot View Post
the Fing app
fping as I posted in the thread before...

jlinkels
 
Old 10-29-2017, 01:20 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by Jackpot View Post
This is the simplest way of performing host discovery is with nmap.

# nmap -sP 192.168.X.X/24
Though setting a static IP address is the easiest, and best, way forward, nmap is really very useful to know. I'd say do both but only begin with nmap after setting the fixed IP.

Since the search is for SSH servers, the usual way would be to check port 22:

Code:
nmap -sT -p 22 -T 4 192.168.x.x/24
However, it really is one of those programs that is too complex for it to be practical to learn all the setting in advance. So instead mastery of navigating the manual page is necessary:

Code:
man nmap
Fortunately it is one of the well-written manual pages.

For what it is worth there is also a specialized tool, scanssh, which can scan for both SSH servers and SOCKS proxies.

Code:
scanssh -n 22 -s ssh 192.168.x.x/24
 
2 members found this post helpful.
Old 10-30-2017, 07:21 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by Turbocapitalist View Post
Though setting a static IP address is the easiest, and best, way forward, nmap is really very useful to know. I'd say do both but only begin with nmap after setting the fixed IP. Since the search is for SSH servers, the usual way would be to check port 22:
Code:
nmap -sT -p 22 -T 4 192.168.x.x/24
However, it really is one of those programs that is too complex for it to be practical to learn all the setting in advance. So instead mastery of navigating the manual page is necessary:
Code:
man nmap
Fortunately it is one of the well-written manual pages. For what it is worth there is also a specialized tool, scanssh, which can scan for both SSH servers and SOCKS proxies.
Code:
scanssh -n 22 -s ssh 192.168.x.x/24
Nice one. Used nmap before, but scanssh is a new one for me, thanks.
 
Old 10-30-2017, 08:14 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by TB0ne View Post
Nice one. Used nmap before, but scanssh is a new one for me, thanks.
No problem. Here are some old links about it:

Last edited by Turbocapitalist; 10-30-2017 at 08:21 AM. Reason: github link
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find Machine serial number of solaris machine? adastane Solaris / OpenSolaris 15 01-09-2012 08:29 AM
LAN hacked - how to find infected machine dlugasx Linux - Security 10 07-03-2009 04:16 PM
lan connection between linux machine and windows machine arunsan842004 Linux - Laptop and Netbook 1 11-25-2008 05:44 AM
LAN machine allelopath Linux - Hardware 1 11-19-2005 02:51 AM
machine has adsl ethernet modem, to make it gateway over lan do i need more lan cards b0nd Linux - Networking 2 10-04-2005 10:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration