The ping command is a network utility used to test connectivity between two devices on a network. It can only ping one device at a time, which can be frustrating. However, some other commands or methods can check the connectivity of multiple devices simultaneously.
In this tutorial, we’ll discuss a few ways to ping multiple IP addresses or hosts at the same time. Also, we’ll use IP addresses and hostnames interchangeably throughout the tutorial.
nping is an open-source command line tool that generates network packets, analyzes responses, and measures response times. We’ll use this command to ping multiple IP addresses at the same time.
To use this command, first, we’ll install nping by using the apt command or its alternatives:
$ apt install nping
Once nping is installed, we can use the -c flag to specify the number of packets to send as well as specific IP addresses or hostnames:
$ nping -c 2 google.com facebook.com Starting Nping 0.7.80 ( https://nmap.org/nping ) at 2023-03-12 21:39 +0545 SENT (0.0020s) Starting TCP Handshake > google.com:80 (18.104.22.168:80) RCVD (0.0266s) Handshake with google.com:80 (22.214.171.124:80) completed SENT (1.0044s) Starting TCP Handshake > facebook.com:80 (126.96.36.199:80) SENT (2.0059s) Starting TCP Handshake > google.com:80 (188.8.131.52:80) RCVD (2.0288s) Handshake with google.com:80 (184.108.40.206:80) completed RCVD (2.0501s) Handshake with facebook.com:80 (220.127.116.11:80) completed SENT (3.0077s) Starting TCP Handshake > facebook.com:80 (18.104.22.168:80) RCVD (3.0483s) Handshake with facebook.com:80 (22.214.171.124:80) completed Statistics for host google.com (126.96.36.199): | Probes Sent: 2 | Rcvd: 2 | Lost: 0 (0.00%) |_ Max rtt: 24.567ms | Min rtt: 22.811ms | Avg rtt: 23.689ms Statistics for host facebook.com (188.8.131.52): | Probes Sent: 2 | Rcvd: 2 | Lost: 0 (0.00%) |_ Max rtt: 1045.663ms | Min rtt: 40.806ms | Avg rtt: 543.234ms TCP connection attempts: 4 | Successful connections: 4 | Failed: 0 (0.00%) Nping done: 2 IP addresses pinged in 3.05 seconds
Here, the nping command generates an output that displays statistics about the packets sent, received (RCVD), and lost, along with the round-trip time (RTT) for each packet. Additionally, the output will display any errors or problems encountered during the process.
In addition to nping, we can use fping, which is another command line tool that allows us to ping multiple destinations simultaneously.
First, let’s install fping by using the apt command:
$ apt install fping
Similar to the nping command, we can supply multiple endpoints and use the -c flag to define the number of packets to send:
$ fping -c 2 google.com facebook.com google.com : , 64 bytes, 23.7 ms (23.7 avg, 0% loss) facebook.com : , 64 bytes, 46.0 ms (46.0 avg, 0% loss) google.com : , 64 bytes, 23.1 ms (23.4 avg, 0% loss) facebook.com : , 64 bytes, 45.2 ms (45.6 avg, 0% loss) google.com : xmt/rcv/%loss = 2/2/0%, min/avg/max = 23.1/23.4/23.7 facebook.com : xmt/rcv/%loss = 2/2/0%, min/avg/max = 45.2/45.6/46.0
The output above shows that the command sends ICMP packets to both google.com and facebook.com. Also, it provides statistics about each host for each ping attempt. For example, the first line shows data for the first attempt to ping google.com. In particular, we see that the size of the packet is 64 bytes, the round trip time is 23.7 ms, the average round trip time is 23.7, and the loss percentage is 0%.
The last two lines show the overall statistics for both attempts per host. It displays the total number of packets transmitted (xmt) and received (rcv), the percentage of packets lost (%loss), and the minimum (min), average (avg), and maximum (max) round trip time for each packet.
4. Bash Scripting
Instead of installing multiple command line tools, we can write a Bash script with the regular ping command that meets our needs.
To begin with, let’s create the bash script and save it as ping_simultaneously.sh:
#!/bin/bash # check if arguments were provided if [ $# -eq 0 ]; then echo "Usage: $0 <hostname or IP address> ..." exit 1 fi # loop through each argument and ping it in the background for host in "$@" do ping -c 1 "$host" & wait done
To execute the script that we created easily, we make the script executable:
$ chmod +x ping_simultaneously.sh
After making it executable, we can run the script with IP addresses or hosts as arguments:
$ ./ping_simultaneously.sh google.com facebook.com Pinging google.com [184.108.40.206] with 32 bytes of data: Reply from 220.127.116.11: bytes=32 time=21ms TTL=113 Ping statistics for 18.104.22.168: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 21ms, Maximum = 21ms, Average = 21ms Pinging facebook.com [22.214.171.124] with 32 bytes of data: Reply from 126.96.36.199: bytes=32 time=47ms TTL=52 Ping statistics for 188.8.131.52: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 47ms, Maximum = 47ms, Average = 47ms
The script sends echo requests, i.e., ICMP packets, to each IP address or host. The output contains information regarding ping statistics such as packet size, round trip time (RTT), loss percentage, and time to live (TTL).
In this article, we’ve explored three ways to ping multiple IP addresses or hosts at once, including powerful tools like nping and fping. These tools provide various functionalities that can be tailored to our specific needs.
Alternatively, we can also create a Bash script. By utilizing these methods, we can save time and ensure that our network is running smoothly.