LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2008, 10:18 AM   #1
userlander
Member
 
Registered: Jul 2008
Distribution: Arch, Debian
Posts: 61

Rep: Reputation: 18
Ban a Range of IPs in iptables


I would like to ban this range of IPs from china:

222.208.0.0 - 222.215.255.255

what is the best way to do that in iptables? I only know how to block individual IPs, but obviously that would take hours if I had to do it one by one! Is there a way to block them all at once?

This is on ipcop, so if there is a better way to do it with some add-on, I wouldn't mind hearing about that, too. I have Banish installed, but again you have to banish by individual IPs (as far as I know).
 
Old 11-13-2008, 10:50 AM   #2
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
For web access you can insert deny from in the Apache configuration:

Code:
deny from 222.208
deny from 222.209
deny from 222.210
deny from 222.211
deny from 222.212
deny from 222.213
deny from 222.214
deny from 222.215
 
Old 11-13-2008, 11:01 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Recent versions of iptables support the IP range using this syntax:
Code:
-m iprange --src-range 222.208.0.0-222.215.255.255
use --dst-range if you want to specify destination addresses.
 
Old 11-13-2008, 12:08 PM   #4
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Other options include using:
  • Netmask notation: 222.208.0.0/255.248.0.0; or
  • CIDR notation: 222.208.0.0/13

You can confirm the range yourself using a calculator: http://www.subnet-calculator.com/cidr.php
 
Old 11-13-2008, 01:07 PM   #5
userlander
Member
 
Registered: Jul 2008
Distribution: Arch, Debian
Posts: 61

Original Poster
Rep: Reputation: 18
Lots of options, excellent thanks.

It turns out Banish can ban by CIDR notation. I don't really know CIDR yet, but I guess 222.208.0.0/24 would ban that entire range, from 0-255, while /23 would also ban the .1.x subnet up to 255. Now just to figure out if there's a way to specify the second grouping of numbers with CIDR.


#-------------->
Thanks anomie - I had my message loaded in quick reply and then got busy. I see you posted in the meantime. But that's exactly what I was wondering about, that calculator will definitely come in handy.

Last edited by userlander; 11-13-2008 at 01:10 PM.
 
  


Reply



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
Can I Ban Certain IPs or Subnets davidstvz Linux - Newbie 8 08-16-2008 09:34 AM
iptables help please with blocking range of IPs lleb Linux - Software 7 02-26-2007 10:09 AM
Best way to ban blocks of IPs? hank43 Linux - Security 4 02-23-2007 02:36 PM
i want to block a range of ips using iptables... Vasili Linux - Security 18 09-19-2006 06:31 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

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration