LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-24-2007, 09:40 AM   #1
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,466

Rep: Reputation: 440Reputation: 440Reputation: 440Reputation: 440Reputation: 440
iptables help please with blocking range of IPs


how do i use iptables to block a large range of IPs from an ISP?

I want to block 220.128.0.0 - 220.143.255.255 from an ISP in Taiwan that is spamming my network via an old virus and causing my little IPCop to work much harder then it needs to.

I am talking several hundred hits per min from the same IP and when i dig deeper into my firewall logs it shows multiple computers from the same ISP hitting my network almost 24/7 for the past week or so.

now granted even if it did breach my firewall, it will do zero damage to my computer (im running OSx at the office and this is a MS virus) so that is not my concern. i just want to block that ISP and be done with them.

I know that if i use the following line i can block out a full range from 0 - 255, but how do i go past the first set of octects? (think that is the correct word for it)

Code:
# blocks HINET from Taipei Taiwan, CHTD, Chugnhwa Telecom Co., Ltd.
/sbin/iptables -A CUSTOMINPUT -s 220.128.0.0/24 -j DROP
but as you see above they have many more IP ranges, then just the 220.128.x.x that i just blocked with that single line. do i have to create a line for every 220.129, 220.130, etc... up to 220.143, or is there a faster, better way? many thanks.
 
Old 02-24-2007, 02:54 PM   #2
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 168

Rep: Reputation: 30
You just need to calculate the CIDR value for the ip range.

The cidr for the example you gave: 220.128.0.0 - 220.143.255.255 will be 220.128.0.0/12.
 
Old 02-24-2007, 03:13 PM   #3
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
i think a line like
$IPTABLES -A INPUT -i eth0 -s 220.128.0.0/220.143.255.255 -j REJECT

is the proper syntax for that after you adjust the interface to the correct one
 
Old 02-24-2007, 05:55 PM   #4
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 168

Rep: Reputation: 30
Quote:
do i have to create a line for every 220.129, 220.130, etc... up to 220.143, or is there a faster, better way? many thanks.
As far as I know, you need a line per ip block.

Quote:
i think a line like
$IPTABLES -A INPUT -i eth0 -s 220.128.0.0/220.143.255.255 -j REJECT
Correct. It can be entered in the format:
$IPTABLES -A INPUT -i eth0 -s 220.128.0.0/12 -j REJECT
and iptables will create it as:
220.128.0.0/220.143.255.255

I use this page to calculate cidr based on ip range:
http://relays.osirusoft.com/cgi-bin/cidr.cgi

Also, if you're looking to reduce spam significantly, you might want to block traffic to port 25 from countries like Korea, China, Hong-Kong, Taiwan, India, Indonesia. See http://www.hakusan.tsg.ne.jp/tjkawa/...er/index-e.jsp

Last edited by fw12; 02-24-2007 at 05:58 PM.
 
Old 02-24-2007, 10:39 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
This is why it's a good practice to deny by default and only allow those subnets that really need access. Once you get into the blacklist game, you may wind up with a long, unwieldy list of rules.

Also, instead of using the REJECT target, use the DROP target. If they're going to hammer you, don't do them the favor of sending back an error packet. Put 'em into the proverbial black hole for a bit.

Last edited by anomie; 02-24-2007 at 10:40 PM.
 
Old 02-24-2007, 10:43 PM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,466

Original Poster
Rep: Reputation: 440Reputation: 440Reputation: 440Reputation: 440Reputation: 440
thanks all, that is great.
 
Old 02-25-2007, 10:05 PM   #7
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 168

Rep: Reputation: 30
Quote:
This is why it's a good practice to deny by default and only allow those subnets that really need access. Once you get into the blacklist game, you may wind up with a long, unwieldy list of rules.
If you're running servers like web/mail, it's impossible to know ahead of time what subnets are going to need access to your machine.

So the only practical way is to list all ip blocks to deny. I have over 1,200 entries that block many Asian countries from connecting to port 25. I don't see any impact of the large file on my machine.
 
Old 02-26-2007, 10:09 AM   #8
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
If you're running servers like web/mail, it's impossible to know ahead of time what subnets are going to need access to your machine.
That's obviously not true in every situation. OP hasn't specified whether his services require him to be open to the world.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i want to block a range of ips using iptables... Vasili Linux - Security 18 09-19-2006 06:31 AM
Blocking certain IPs with iptables - what am I doing wrong? thinksincode Linux - Security 2 12-21-2004 10:27 AM
how to define a specific range of IPs and/or multiple IPs in an iptables rule?... TheHellsMaster Linux - Security 9 09-20-2004 10:06 AM
Blocking A Class of Ips w/ Iptables kemplej Linux - Security 4 09-03-2004 11:02 AM
Troubles blocking single IPs using IPtables dave_blob Linux - Networking 5 04-04-2004 06:07 AM


All times are GMT -5. The time now is 01:57 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration