fping is one my favorite network profiling / scripting tool. It uses the Internet Control Message Protocol (ICMP) echo request to determine if a target host is responding or not.

Unlike ping , fping is meant to be used in scripts, so its output is designed to be easy to parse.

You can easily write perl / shell script to check a list of hosts and send mail if any are unreachable.

fping command example

Just type the following command to see if we can reach to router:
$ fping router

router is alive

You can read list of targets (hosts / servers) from a file. The -f option can only be used by the root user. Regular users should pipe in the file via
I/O redirectors (stdin). For example read all host names from ~/.ping.conf file
$ fping

You can also netmask to ping the entire network i.e generate a target list from a supplied IP netmask. For example, ping the class C 192.168.1.x:
$ fping -g
$ fping -g

Sample shell script to send email if host is down

HOSTS="router sun printer laptop sony-laptop xbox backup-server"
for h in $HOSTS
  fping -u $h >& /dev/null
  if [ $? -ne 0 ]; then
          echo ${h} host is down send email
          # mail -s "Host ${h} down" admin@you.com </dev/null

Another good example is when you want to perform an action only on hosts that are currently reachable.

$myHosts = ‘cat /etc/hosts.backup | fping -a‘;
foreach $host (split(/\n/,$myHosts)) {
        # take action or call other function

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • ARS Oct 13, 2016 @ 13:38

    Thank you so much. full path of binary resolved the issue

  • Steely Apr 5, 2012 @ 16:37

    Using the full path for fping did the trick. Thank you!

  • Steely Apr 4, 2012 @ 17:26

    Hi Vivek,
    First of all, thank you for all of the great nix guides which you have posted. I use them all the time.

    So I am a somewhat new network admin and I am administering some Fedora 16 boxes. I really like your script here, so I have put it on my testing server (which I use for testing new scripts and software before putting them on the important servers). When I run the script myself, it works perfectly. However, when I run it from crontab, it sends the error emails even though all the hosts I have put into the script are definitely up.

    Is there something about crontab which makes this script work differently?


    • 🐧 nixCraft Apr 5, 2012 @ 5:58

      Set the full path to binaries i.e. fping command. Also, check your cron log file in /var/log directory.

  • 🐧 nixCraft Jan 3, 2008 @ 20:53

    cat ping.conf

  • Ren Jan 3, 2008 @ 20:36

    Show us an example of your ping.conf file contents.

  • 🐧 nixCraft Nov 26, 2007 @ 9:09

    @Rishi, Download FPING RHEL / CentOS / Fedora Package –

  • Rishi kapur Nov 26, 2007 @ 8:31

    It’s good tool but it is not in-built in redhat.
    [root@server1 scripts]# fping
    -bash: fping: command not found

    from where can I download.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz