Ping Multiple Host With Fping Command
In Linux or any OS while working in office or any other network, sometime we need to check connectivity of remote machine might, usually we used to work with ping tool to test connectivity of machine or device that has some IP range, So most of device support ICMP to send and reply through ping request. In this post we will How to Ping Multiple Host With Fping Command.
Sometime we need to ping multiple host on same time. But we have usual ping tool which has only have one host provision or in case we need to ping we can run it in loop which is not very presentable to normal user, we can write some according to situation, which could make ping more visible for normal user.
how ping work
Usually we used to machine connectivity through some basic ping test like below
▶ ping -c 1 10.36.1.3 PING 10.36.1.3 (10.36.1.3) 56(84) bytes of data. 64 bytes from 10.36.1.3: icmp_seq=1 ttl=64 time=0.427 ms --- 10.36.1.3 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.427/0.427/0.427/0.000 ms
But what if we need to ping complete subnet and we just need to know is machine is reachable through network or not. I usually like to write something my own for such cases like below
▶ for i in `echo 10.36.1.{1..5}`; do ; echo -n "$i ---- " ;ping -c 1 -w 1 $i &> /dev/null && echo online || echo offline ; done 10.36.1.1 ---- online 10.36.1.2 ---- online 10.36.1.3 ---- online 10.36.1.4 ---- offline 10.36.1.5 ---- offline
Through Above way we have pinged some range of IPs and also able to skip summary after ping and instead of summary it show us in more presentable way like either machine is online or offline (reachable or unreachable).
So i think we need a tool which should has various kind of options for such range of different usage which ping command not supported by-default. So fping is same kind of command-line tool which could used to ping multiple hosts in one shot without need of any pattern or regex etc. Here we can use fping command Tool.
Ping multiple hosts
Through fping we can perform ping on multiple hosts in such , by default it will only inform are these machines are alive or not.
ssirohi@jarvis:~$ fping google.com yahoo.com amazon.com google.com is alive amazon.com is alive yahoo.com is alive
In case any host is not reachable, it will reply like below
ssirohi@jarvis:~$ fping google.com yahoo.com amazon.com facehook.com google.com is alive amazon.com is alive yahoo.com is alive facehook.com is unreachable
In case we need to human readable summary of it, we can use it like below.
ssirohi@jarvis:~$ fping -s google.com yahoo.com amazon.com facehook.com google.com is alive amazon.com is alive yahoo.com is alive facehook.com is unreachable 4 targets 3 alive 1 unreachable 0 unknown addresses 1 timeouts (waiting for response) 7 ICMP Echos sent 3 ICMP Echo Replies received 0 other ICMP received 7.15 ms (min round trip time) 76.7 ms (avg round trip time) 141 ms (max round trip time) 4.107 sec (elapsed real time)
We can also do ping with list of elements, But list should be like first and last elements only like mentioned in below command. We used to start ping from first till last IP provided. We can also ping complete Subnet as well, with below way. Your subnet could quit large and possibly many of machine are not reachable in these scenario in this we could redirect unreachable host information to null and could only display reachable IPs. We can also ask fping command to read list of IPs or host-name from file like below. These list is maintained one IP per line. We can also try to apply timeout in case we know that some of Hosts are not reachable or will not respond on time. In above command, we use timeout value(by-default 500) of 100 millisecond and only one try (by-default: 3). This will help when we need to ping multiple host and possibility that some of host will not reply on time or not reachable.
ssirohi@jarvis:~$ fping -s -g 157.240.1.35 157.240.1.40
157.240.1.35 is alive
157.240.1.36 is alive
157.240.1.37 is alive
157.240.1.38 is alive
157.240.1.39 is alive
ICMP Network Unreachable from 2.127.241.149 for ICMP Echo sent to 157.240.1.40
ICMP Network Unreachable from 2.127.241.149 for ICMP Echo sent to 157.240.1.40
ICMP Network Unreachable from 2.127.241.149 for ICMP Echo sent to 157.240.1.40
ICMP Network Unreachable from 2.127.241.149 for ICMP Echo sent to 157.240.1.40
157.240.1.40 is unreachable
6 targets
5 alive
1 unreachable
0 unknown addresses
1 timeouts (waiting for response)
9 ICMP Echos sent
5 ICMP Echo Replies received
4 other ICMP received
6.28 ms (min round trip time)
7.02 ms (avg round trip time)
8.14 ms (max round trip time)
4.127 sec (elapsed real time)
Ping complete Subnet
▶ fping -a -g -r 1 10.36.1.13/24 2> /dev/null
10.36.1.1
10.36.1.2
10.36.1.3
10.36.1.13
10.36.1.15
10.36.1.16
10.36.1.18
10.36.1.100
10.36.1.101
Read list from file
▶ fping < sd
10.36.1.1 is alive
10.36.1.2 is alive
10.36.1.3 is alive
10.36.1.13 is alive
10.36.1.15 is alive
10.36.1.16 is alive
10.36.1.18 is alive
10.36.1.100 is alive
10.36.1.101 is alive
Ping Retry and timeout
ssirohi@jarvis:~$ fping -t100 -r 1 yahoo.com google.com facehook.com geekpills.com
google.com is alive
geekpills.com is alive
yahoo.com is alive
facehook.com is unreachable
Leave a Reply