block consecutive IP address using scripts



How to block long list of consecutive IP address?
How to call linux route command inside a script?
How to block consecutive IP address using bash script or perl script?
How to block local IP address permanently?

The are times that a server does not need to listen and process any TCP/UDP request for a long list of consecutive local IP addresses.

This blog entry provides a starting point of creating server scripts to block a long list of consecutive IP address from the server for permanent blocking.

To start, launch your fave editor and create a IPblock.sh bash script like with contents similar to the next few lines. This blog entry assumes that you have bash shell and perl currently installed from the machine.
From below example, we are permanently blocking IP address from
192.168.0.10 to 192.168.0.254.
Here's a simple sample script that does the job.
#!/bin/bash
echo Blocking started ...

for ((i=10;i<=254;i=i+1)); do /sbin/route add -host 192.168.0.$i reject done echo Done
This can also be accomplished using perl script which does the same function. Create a separate IPblock.pl perl script like so.
#!/usr/bin/perl -w

my $i;
for ($i=10; $i<=254; $i++ ) { system ("/sbin/route del -host 192.168.0.$i reject"); } }
Make sure these scripts are root executable like so
# chmod 700 IPblock.sh
# chmod 700 IPblock.pl
Now, to execute individually
# ./IPblock.sh
# ./IPblock.pl
Additionally, the above scripts can be scheduled for regular execution if you need them so by using crontab utility.




Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

16 comments:

Mobile App Developers said...

Great article, Thanks for your great information, the content is quiet interesting. I will be waiting for your next post.

Anonymous said...

Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info! , Regards, servicenow training in hyderabad

jatin tyagi said...

I have been reading out a lot of your articles.
I will certainly bookmark your Blog.
Free Devops Training
Dell Boomi Training

GST Registration in Delhi said...

Nice post, things explained in details. Thank You.

John Nash said...

Excellent Blog very imperative good content, this article is useful to beginners and real time Employees. DevOps Online Training

Interview Gig said...

This is an awesome post. Really very informative and creative contents. These concept is a good way to enhance the knowledge. Here You can find some Frequently Asked DevOps Interview Questions and Answers with explanation

Chef Interview Questions and Answers

Docker Interview Questions and Answers

GIT Interview Questions and Answers

Jenkins Interview Questions and Answers

Maven Interview Questions and Answers

Nagios Interview Questions and Answers

Puppet Interview Questions and Answers

nasreen basu said...

interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts,Thanks a million once again, Regardsadobe cq5 training in hyderabad
servicenow training in hyderabad
devops training in hyderabad

santhosh k said...

The blog gave me idea to block consecutive IP address using scripts my sincere thanks for sharing
this post please continue to share this post
Devops Training in Bangalore
Devops Training in BTM Layout
Devops Training in Marathahalli

Sadiya Moshin said...

Block consecutive IP address using bash script or perl script.. Nicely Explained with images.. Great Job!!
Devops Training
Machine Learning Training

arvind said...

Thanks for sharing this informative blog..
best dijango training in Bangalore.

Solomon said...

Thanks for sharing this wonderful blog..best selenium training in bangalore

viswanath said...

very good blog blockchain training in bangalore
python training in bangalore

Suresh R said...

Excellent blog artificial intelligence training in bangalore

mary Brown said...

I am technology Enthusiast. Your blog is really awesome, attractive and impressive. I like the way you think. it is very useful for Java SE & Java EE Learners. Your article adds best knowledge to our Java Online Training in India. or learn thru Java Online Training in India Students. or learn thru JavaScript Online Training in India. Appreciating the persistence you put into your blog and detailed information you provide. Kindly keep blogging.

DAVIS MILLER said...

Those guidelines additionally worked to become a good way to
recognize that other people online have the identical fervor like mine
to grasp great deal more around this condition.


AWS Training in Bangalore


AWS Training in Bangalore

Renith Harsan said...

Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here"Oracle Training in Chennai".

Post a Comment

Popular Posts