How can I ping multiple IP addresses at the same time?
I’m aware of the methods where you can run a Bash for loop and ping multiple servers, is there a Linux CLI tool that I can use which will allow for me to do this without having to resort to writing a Bash script to ping a list of servers one at a time? Something like this:
NOTE: I’m looking specifically for CentOS/Fedora, but if it works on other distros that’s fine too.
Why are you against a little one-liner script doing that — the beauty and philosophy of Linux ;-)? (Have small, simple programs and write the glue for special needs yourself.)
It’s far easier to install a package from a repo vs. copying a script to 2000+ VMs 8-). I could easily write a script solution for myself. Also since I self-answered this I’m creating content on the Internet since I have users whom are asking for a single cmd vs. a shell script and were unsuccessful in finding a simple A’er to what they perceive as a basic Q.
@HagenvonEitzen — nope, I’m installing tooling on 2000+ VMs so that users have tooling available to them to do such.
12 Answers 12
If you look into the NMAP project you’ll find that it includes additional tools on top of just nmap . One of these tools is nping , which includes the following ability:
- Custom TCP, UDP, ICMP and ARP packet generation.
- Support for multiple target host specification.
- Support for multiple target port specification.
- .
nping is in the standard EPEL repos to boot.
$ repoquery -qlf nmap.x86_64 | grep nping /usr/bin/nping /usr/share/man/man1/nping.1.gz
Usage
To ping multiple servers you merely have to tell nping the names/IPs and which protocol you want to use. Here since we want to mimic what the traditional ping CLI does we’ll use ICMP.
$ sudo nping -c 2 --icmp scanme.nmap.org google.com Starting Nping 0.7.70 ( https://nmap.org/nping ) at 2019-06-14 13:43 EDT SENT (0.0088s) ICMP [10.3.144.95 > 45.33.32.156 Echo request (type=8/code=0) seq=1] IP [ttl=64 iplen=28 ] RCVD (0.0950s) ICMP [45.33.32.156 > 10.3.144.95 Echo reply (type=0/code=0) seq=1] IP [ttl=46 iplen=28 ] SENT (1.0091s) ICMP [10.3.144.95 > 45.33.32.156 Echo request (type=8/code=0) seq=2] IP [ttl=64 iplen=28 ] SENT (2.0105s) ICMP [10.3.144.95 > 45.33.32.156 Echo request (type=8/code=0) seq=2] IP [ttl=64 iplen=28 ] RCVD (2.0107s) ICMP [45.33.32.156 > 10.3.144.95 Echo reply (type=0/code=0) seq=2] IP [ttl=46 iplen=28 ] SENT (3.0138s) ICMP [10.3.144.95 > 64.233.177.100 Echo request (type=8/code=0) seq=2] IP [ttl=64 iplen=28 ] Statistics for host scanme.nmap.org (45.33.32.156): | Probes Sent: 2 | Rcvd: 2 | Lost: 0 (0.00%) |_ Max rtt: 86.053ms | Min rtt: 0.188ms | Avg rtt: 43.120ms Statistics for host google.com (64.233.177.100): | Probes Sent: 2 | Rcvd: 0 | Lost: 2 (100.00%) |_ Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A Raw packets sent: 4 (112B) | Rcvd: 2 (108B) | Lost: 2 (50.00%) Nping done: 2 IP addresses pinged in 3.01 seconds
The only drawback I’ve found with this tool is the use of ICMP mode requiring root privileges.
$ nping -c 2 --icmp scanme.nmap.org google.com Mode ICMP requires root privileges.
How to ping all the ip in LAN using Terminal?
I am trying to ping all the systems available in the local area network using terminal command. Can any one tell me how to do this?
4 Answers 4
You can install an application called nmap .
Then you can check your entire network for all connected IP addresses by typing in the following:
The above command will scan all IP addresses starting at 192.168.1.1 through 192.168.1.254 and show you all IPs that responded.
You can scan other IP address ranges like 192.168.0.1 — 192.168.1.254 by typing in the following:
A typical scan might return something like the following:
terrance@terrance-ubuntu:~$ nmap -sP 10.0.0.1/24 Starting Nmap 6.40 ( http://nmap.org ) at 2015-12-24 00:20 MST Nmap scan report for Linksys03773 (10.0.0.1) Host is up (0.00078s latency). Nmap scan report for terrance-ubuntu (10.0.0.100) Host is up (0.00020s latency). Nmap scan report for android (10.0.0.148) Host is up (0.099s latency). Nmap scan report for PC (10.0.0.149) Host is up (0.0014s latency). Nmap scan report for 10.0.0.150 Host is up (0.0016s latency). Nmap scan report for 10.0.0.165 Host is up (0.011s latency). Nmap scan report for 10.0.0.169 Host is up (0.010s latency). Nmap scan report for 10.0.0.179 Host is up (0.014s latency). Nmap scan report for android (10.0.0.181) Host is up (0.093s latency). Nmap scan report for android (10.0.0.188) Host is up (0.043s latency). Nmap scan report for android (10.0.0.196) Host is up (0.014s latency). Nmap scan report for 10.0.0.253 Host is up (0.0013s latency). Nmap done: 256 IP addresses (12 hosts up) scanned in 4.46 seconds
Linux : Ping all the host in the subnet
Is there anything similar to this one in linux ? My intention is to find one mac address as below after pinging all the hosts:
3 Answers 3
All you are doing is pinging the broadcast address. The GNU/Linux version of ping requires that you use the -b switch
-b Allow pinging a broadcast address
There doesn’t appear to be a direct equivalent of the Solaris -s switch either (it’s only pinging every second and gathering stats) but perhaps it’s buried in the Linux man pages- well worth a read (as may be the Solais ones ).
I wouldn’t go pinging 255.255.255.255 either (it may take a while to complete) I’d use the broadcast address of the network I was connected to.
You can always try to ping to the broadcast address of your subnet. It depends on your local network setup, but you can find it out with
$ ifconfig wlp4s0 | grep Bcast inet addr:192.168.199.47 Bcast:192.168.199.255 Mask:255.255.255.0
Pinging from Linux requires the -b commandline switch, which is kind of a precaution of the command.
However, this does not guarantee that you will collect all MAC addresses from all devices connected to your subnet as it is up the the very device to actually answer ICMP ECHO requests sent to broadcast addresses, even if that was intended otherwise in the early ages of the TCP/IP RFCs (see whether /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts is set to 1).
To be more sure to cover all addresses, ping them individually with
$ for ip in 192.168.199.; do ping -c1 $ & done
More or less the same is achieved if you use a special scan type of nmap with
$ sudo nmap -sn -PE -n 192.168.179.1-254
That is also my recommended way of probing since you can fine tune the way you ask the clients for their MAC addresses.