Linux / UNIX: Ping a Block of Hosts (netblock)

Q. How do I ping a block of hosts such as 192.168.1.0/24?

ADVERTISEMENTS

A. You can use ping or fping. The -g option generate a target list from a supplied IP netmask, or a starting and ending IP. Specify the netmask or start/end in the targets portion of the command line.

fping command

To ping the class C 192.168.1.0/24, the specified command line could look like either:
$ fping -g 192.168.1.0/24
OR
$ fping -g 192.168.1.0 192.168.1.255

ping command

You can also use ping command, enter:

for i in {1..254}; do ping -c1 192.168.1.$i; done

There are other options like nmap, nbtscan, Windows NT / Server specific loop discussed here.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
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

ADVERTISEMENTS
6 comments… add one
  • someone Jan 8, 2009 @ 15:50

    It should be like this command:

    for i in {1..254}; do ping -c1 192.168.1.$i; done

  • 🐧 nixCraft Jan 8, 2009 @ 16:20

    Thanks for the heads up.

  • elinusliga Jan 9, 2009 @ 6:12

    Perfect…thank you for the post.

  • Rafael Bezerra do Nascimento Jan 9, 2009 @ 13:04

    I use Nmap
    # nmap -sP 192.168.0.*
    or
    # nmap -sP 192.168.0.1-200

  • Mark Sanborn Jan 14, 2009 @ 17:42

    That is awesome. Also like the nmap version :)

  • Jasleen May 10, 2009 @ 13:50

    what about the same procedure in RHEL 5

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.