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

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.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 6 comments… read them below or add one }

1 someone 01.08.09 at 3:50 pm

It should be like this command:

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

2 Vivek Gite 01.08.09 at 4:20 pm

Thanks for the heads up.

3 elinusliga 01.09.09 at 6:12 am

Perfect…thank you for the post.

4 Rafael Bezerra do Nascimento 01.09.09 at 1:04 pm

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

5 Mark Sanborn 01.14.09 at 5:42 pm

That is awesome. Also like the nmap version :)

6 Jasleen 05.10.09 at 1:50 pm

what about the same procedure in RHEL 5

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , ,

Previous post: SSH System Bootup In Progress Please Wait Error and Solution

Next post: Red Hat / CentOS: Check / List Running Services