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

Posted on in Categories , , , , , , , , , , , last updated January 8, 2009

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

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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

6 comment

Leave a Comment