How to use ping, fping, and gping for various purpose in Linux

Whenever users come to know their website or server is down, immediately they will fire ping command to verify that a host computer can connect to the TCP/IP network and network resources. Ping is a vast tool which was used by everyone around the world.

Only part of peoples know about fping, especially network administrator aware of this since it’s used to check entire network availability.

Most of the people doesn’t know much about gping but it’s not a big deal. It’s same as ping with a graph.Today we are going to cover about ping, fping, and gping usage for varies purpose.

What is Ping & How to use it

ping stands for (Packet Internet Groper) command, is a networking utility that used to test the target of a host availability/connectivity on an Internet Protocol (IP) network. It’s verify a host availability by sending Internet Control Message Protocol (ICMP) Echo Request packets to the target host and waiting for an ICMP Echo Reply. It summarize statistical results based on the packets transmitted, packets received, packet loss, typically including the min/avg/max times.

In Linux, by default it keeps sending the packets until you hit CTRL-C to terminate the ping command output. So add -c option which automatically terminate ping after N number of packets. Ping is pre-installed on most of Linux distributions so no need to worry, simply fire the following commands to get it work.

1) Ping the local host: To ping local host.

# ping 0 -c 4
PING 0 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.044 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.056 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.040 ms

--- 0 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.040/0.045/0.056/0.008 ms

2) Ping the host: To ping target host connectivity.

# ping -c 4 2daygeek.com
PING 2daygeek.com (104.27.156.177) 56(84) bytes of data.
64 bytes from 104.27.156.177: icmp_seq=1 ttl=53 time=21.5 ms
64 bytes from 104.27.156.177: icmp_seq=2 ttl=53 time=20.9 ms
64 bytes from 104.27.156.177: icmp_seq=3 ttl=53 time=20.9 ms
64 bytes from 104.27.156.177: icmp_seq=4 ttl=53 time=21.0 ms

--- 2daygeek.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 20.932/21.104/21.508/0.256 ms

3) Quiet ping: Print only Summary Statistics, nothing is displayed except the summary lines at startup time and when finished.

# ping -c 4 -q 2daygeek.com
PING 2daygeek.com (104.27.157.177) 56(84) bytes of data.

--- 2daygeek.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 20.869/20.968/21.057/0.076 ms

4) Audible ping: It simply gives a beep sound when the target host is reachable.

# ping -c 4 -a 2daygeek.com
PING 2daygeek.com (104.27.156.177) 56(84) bytes of data.
64 bytes from 104.27.156.177: icmp_seq=1 ttl=53 time=20.9 ms
64 bytes from 104.27.156.177: icmp_seq=2 ttl=53 time=20.9 ms
64 bytes from 104.27.156.177: icmp_seq=3 ttl=53 time=20.9 ms
64 bytes from 104.27.156.177: icmp_seq=4 ttl=53 time=20.9 ms

--- 2daygeek.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 20.907/20.933/20.987/0.179 ms

5) ping multiple host: Even we can ping multiple host at once.

# ping -c 4 2daygeek.com && ping -c 4 magesh.co.in
PING 2daygeek.com (104.27.157.177) 56(84) bytes of data.
64 bytes from 104.27.157.177: icmp_seq=1 ttl=53 time=20.9 ms
64 bytes from 104.27.157.177: icmp_seq=2 ttl=53 time=21.0 ms
64 bytes from 104.27.157.177: icmp_seq=3 ttl=53 time=21.1 ms
64 bytes from 104.27.157.177: icmp_seq=4 ttl=53 time=21.4 ms
 
--- 2daygeek.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 20.904/21.135/21.460/0.255 ms
PING magesh.co.in (103.212.204.46) 56(84) bytes of data.
64 bytes from ns1.cloudsolz.com (103.212.204.46): icmp_seq=1 ttl=55 time=273 ms
64 bytes from ns1.cloudsolz.com (103.212.204.46): icmp_seq=2 ttl=55 time=245 ms
64 bytes from ns1.cloudsolz.com (103.212.204.46): icmp_seq=3 ttl=55 time=246 ms
64 bytes from ns1.cloudsolz.com (103.212.204.46): icmp_seq=4 ttl=55 time=245 ms

--- magesh.co.in ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 245.713/252.843/273.605/11.993 ms

What’s fping & How to use it

fping is a program like ping which uses the Internet Control Message Protocol ( ICMP ) echo request to determine if a target host is responding. fping differs from ping since it’s allow users to ping any number of hosts in parallel. Also you can input a hosts from txt file.

fping will send out a ICMP echo request and move on to the next target in a round-robin fashion and doesn’t wait until target host replies. If a target host replies, it is noted as active and removed from the list of targets to check. If a target does not respond within a certain time limit and/or retry limit it is designated as unreachable.

How to install fping on Linux

fping is available in the default repositories of most Linux distributions but it’s not pre-installed, so use package manager to install it.

For Debian/Ubuntu systems, use APT-GET command or APT Command to install fping.

$ sudo apt-get install fping

For RHEL/CentOS systems, enable EPEL Repository and use YUM Command to install fping.

$ sudo yum install fping

For Fedora systems, use DNF Command to install fping.

$ sudo dnf install fping

For Arch Linux system, use Pacman Command to install fping since it’s available from distribution official repository.

$ sudo pacman -S fping

For openSUSE system, use Zypper Command to install fping.

$ sudo zypper install fping

1) To ping multiple host, mention the host between spaces

# fping 2daygeek.com magesh.co.in
2daygeek.com is alive
magesh.co.in is alive

2) To Display targets by address instead fo DNS name.

# fping -A 2daygeek.com magesh.co.in
104.27.156.177 is alive
103.212.204.46 is alive

3) Print the output with IP and (if available) the hostname.

# fping -A -d 2daygeek.com magesh.co.in
2daygeek.com (104.27.157.177) is alive
magesh.co.in (103.212.204.46) is alive

4) To scan range of IP addresses from x.x.x.x to x.x.x.x

# fping -s -g 10.30.0.1 10.30.0.10 -r 1
10.30.0.1 is alive
10.30.0.2 is alive
10.30.0.10 is alive
10.30.0.3 is unreachable
10.30.0.4 is unreachable
10.30.0.5 is unreachable
10.30.0.6 is unreachable
10.30.0.7 is unreachable
10.30.0.8 is unreachable
10.30.0.9 is unreachable

      10 targets
       3 alive
       7 unreachable
       0 unknown addresses

       7 timeouts (waiting for response)
      17 ICMP Echos sent
       3 ICMP Echo Replies received
       0 other ICMP received

0.34 ms (min round trip time)
0.35 ms (avg round trip time)
0.38 ms (max round trip time)
        1.477 sec (elapsed real time)

5) To print only alive host.

# fping -s -g 10.30.0.1 10.30.0.10 -r 1 -a
10.30.0.1
10.30.0.2
10.30.0.10

      10 targets
       3 alive
       7 unreachable
       0 unknown addresses

       7 timeouts (waiting for response)
      17 ICMP Echos sent
       3 ICMP Echo Replies received
       0 other ICMP received

0.35 ms (min round trip time)
0.39 ms (avg round trip time)
0.42 ms (max round trip time)
        1.476 sec (elapsed real time)

6) To scan Specific network (/24 – 254 hosts)

# fping -g 10.30.0.1/24
10.30.0.1 is alive
10.30.0.2 is alive
10.30.0.12 is alive
10.30.0.15 is alive
10.30.0.17 is alive
10.30.0.31 is alive
10.30.0.32 is alive
10.30.0.55 is alive
10.30.0.56 is alive
10.30.0.57is alive
10.30.0.58 is alive
.
.
.

7) Read list of targets from a file. This option can only be used by the root user.

# fping -f 2g-sites.txt
2daygeek.com is alive
magesh.co.in is alive

What is gping & How to use it

Gping is a cross-platform ping tool that displays a color coded realtime graph of continuous pings to a specified host. By default it’s ping Google.com when you doesn’t specify a host.

Linux users can install gping using snap.

$ sudo snap install gping && snap connect gping:network-observe

Alternatively, we can install from pip package. Tested with Python 3.4 and 2.7.

[For Python 2.x]
$ sudo pip install pinggraph

[For Python 3.x]
$ sudo pip3 install pinggraph

By default, it’s ping google.com

$ gping

To ping any other host.

$ gping 2daygeek.com

Leave a Reply

Your email address will not be published. Required fields are marked *