Linux for Network Engineers: How to use fping

By February 10, 2021Linux

To summarize my coverage of the ping-verse, so far on the NetBeez blog, I have covered four different utilities: ping, nping, prettyping, gping. In this post, I am continuing with fping. And there is even more ping goodness coming your way soon…

Fping stands for fast ping, and its main differentiation with the regular ping is that it gives you the ability to scan a list of hosts (either coming from a file, an IP range, or a subnet) and tells you which ones are alive. Other than that, it can do pretty much everything the good old ‘original’ ping can do in terms of latency, configuring payload, IPv4/IPv6, etc.

Installation

Fping is available to install on Debian based linux with:

However, I’d recommend to follow the instructions on the project’s github page here in order to download and install the latest version. Here is how I installed version 5.0:

Basic Usage

The most basic task fping can do is tell you if a host is alive or not, as follows:

As you can see it doesn’t even return the latency. Note that you have to run fping as a root user.

To get the continuous pinging functionality that the regular ping does by default you have to add the -l flag as follows:

The reason fping is called “fast” is because you can specify the interval between the ping packets down to the millisecond with the -p flag. To demonstrate this I am adding the -D option that prints the timestamp of each packet sent:

In this example, I am pinging google.com with a period of 20 milliseconds. The interesting observation is that the first ten or so packets get a response, and after that google.com stops responding. My assumption is that if Google detects such a low pinging period, it rate limits the responses to avoid DDoS attacks. If you try the same ping with a local host in your network, you won’t see this behavior. Keep in mind that when you use the  -p flag the timeout time is less or equal to the period (e.g. if you sed a period of 1 millisecond and the host doesn’t respond within 1 millisecond, then that ping test will be considered as a failed one).

Host Scanning

For me, one of the most useful features of fping is the quick host discovery within a subnet or within an IP range with the generate-list option -g. Here is an example.

I find this output to be too verbose. Usually, I am interested in discovering all pingable hosts in a subnet, and here is how I do it.

This uses the quiet flag -q, only targets that are alive with  -a, and also prints a summary of statistics at the end with -s.

Additionally, fping can take as input a file that has a list of target hosts. As an example, I have the following file

And I can ask fping to ping all these hosts to check if they are alive with:

Or I can run continuous ping tests with:

Note that when fping sends ICMP requests to multiple hosts, it does that in parallel without waiting for one host to respond and then move to the next one.

Fping has several other options, but not too many to be overwhelming. They are available under fping --help.

netbeez-monthly-webinar