Network tips on Linux

Find hosts connected to a network

The Nmap (short form for Network Mapper) is an open source, powerful and a very versatile command line tool for exploring networks, perform security scans, network audit and finding open ports on remote machine and so much more.

sudo apt-get install nmap

Once you have Nmap installed, the syntax for using it is:

nmap  [scan type...]  options  {target specification}

Where the argument {target specification}, can be replaced by hostnames, IP addresses, networks and so on.

Therefore to list the IP addresses of all hosts connected to a given network, first of all identify the network and its subnet mask using the ifconfig command or ip command like so:

fabgt@fabgt-SAT:~$ nmap -sn 192.168.1.0/24
Starting Nmap 7.92 ( https://nmap.org ) at 2021-12-30 15:07 CET
Nmap scan report for dsldevice.lan (192.168.1.1)
Host is up (0.25s latency).
Nmap scan report for 192.168.1.100
Host is up (0.85s latency).
Nmap scan report for 192.168.1.101
Host is up (1.4s latency).
Nmap scan report for 192.168.1.114
Host is up (0.059s latency).
Nmap scan report for fabgt-SAT.lan (192.168.1.156)
Host is up (0.00025s latency).
Nmap scan report for MyDiskstation.lan (192.168.1.164)
Host is up (0.78s latency).
Nmap scan report for ESP_D1B826.lan (192.168.1.236)
Host is up (2.9s latency).
Nmap done: 256 IP addresses (7 hosts up) scanned in 42.69 seconds

In the command above:

-sn is the type of scan, which means a ping scan. By default, Nmap performs port scanning, but this scan will disable port scanning. 10.42.0.0/24 is the target network, replace it with your actual network.