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/bashThis can also be accomplished using perl script which does the same function. Create a separate IPblock.pl perl script like so.
echo Blocking started ...
for ((i=10;i<=254;i=i+1)); do /sbin/route add -host 192.168.0.$i reject done echo Done
#!/usr/bin/perl -wMake sure these scripts are root executable like so
my $i;
for ($i=10; $i<=254; $i++ ) { system ("/sbin/route del -host 192.168.0.$i reject"); } }
# chmod 700 IPblock.shNow, to execute individually
# chmod 700 IPblock.pl
# ./IPblock.shAdditionally, the above scripts can be scheduled for regular execution if you need them so by using crontab utility.
# ./IPblock.pl
![Digg](http://1.bp.blogspot.com/_lxBSX0YJV58/SwQiO9krTcI/AAAAAAAAAhc/80Z-NLrZ7wU/s1600/digg.png)
![Google Bookmarks](http://1.bp.blogspot.com/_lxBSX0YJV58/SwQitItySOI/AAAAAAAAAhs/RQQh6Du9HrA/s1600/google.png)
![reddit](http://1.bp.blogspot.com/_lxBSX0YJV58/SwQitlmYSuI/AAAAAAAAAh8/mTtVHQxL_mE/s1600/reddit.png)
![Mixx](http://2.bp.blogspot.com/_lxBSX0YJV58/SwQitawG7PI/AAAAAAAAAh0/vF4HOlj8JH8/s1600/mixx.png)
![StumbleUpon](http://2.bp.blogspot.com/_lxBSX0YJV58/SwQit6IUS5I/AAAAAAAAAiE/gfbBSYnbjnU/s1600/stumbleupon.png)
![Technorati](http://4.bp.blogspot.com/_lxBSX0YJV58/SwQiuP6h64I/AAAAAAAAAiM/x_aGzBKYCgc/s1600/technorati.png)
![Yahoo! Buzz](http://1.bp.blogspot.com/_lxBSX0YJV58/SwQi2FtKY5I/AAAAAAAAAiU/ByTK_Wci_Uo/s1600/yahoo.png)
![DesignFloat](http://4.bp.blogspot.com/_lxBSX0YJV58/SwQiOmnjWDI/AAAAAAAAAhU/nMIbaOaCDic/s1600/designfloat.png)
![Delicious](http://4.bp.blogspot.com/_lxBSX0YJV58/SwQiOHLlI8I/AAAAAAAAAhM/6JP39Dh6sF8/s1600/delicious.png)
![BlinkList](http://3.bp.blogspot.com/_lxBSX0YJV58/SwQiN859bNI/AAAAAAAAAhE/E_Uh6XTQmpo/s1600/blinklist.png)
![Furl](http://3.bp.blogspot.com/_lxBSX0YJV58/SwQiPG9Y6xI/AAAAAAAAAhk/YzmjQUPdnrg/s1600/furl.png)