- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsI've migrated my mail and web services from a FreeBSD/PF environment to Linux/iptables (CentOS 5.3).
Being relatively new to iptables, I sought a pre-configured setup to facilitate a quicker rollout - I found a script called "ipkungfu" (which is no longer being developed). This post is not about that script, so much as it is a question about how to utilize iptables effectively.
Along with my configuration I have a few tables of IPs (mostly /24's) from my PF configuration, tables of: abuse, spammers and geoip. The abuse table are IPs that I never, ever want touching any services on my system. Spammers, blocked from port 25. Geoip, is generally no access as well.
Iptables has three basic initial chains:
INPUT
FORWARD
OUTPUT
I set up a custom script that would do a for-next loop through the IPs and do something like this:
$iptables -I abuse -s $i -j DROP
I found this isn't working. I also found that loading large IP lists into iptables is painfully slow (it was lightning fast under FreeBSD/PF).
One particularly annoying host from netsync.net had been slamming my system repeatedly. The IP was in the DROP directive, but it was getting through anyway. This, I thought, was due to the fact that some of my services are FORWARDed to an internal host and thus perhaps bypassing something. I was able to block this host by issuing this command:
# iptables -A FORWARD -s 208.20.34.161 -j DROP
# iptables -A FORWARD -s 208.20.34.150 -j DROP
So my predicament is in correctly understanding how to effectively block these large lists of IPs. Some of them are BOTNETs some of them are /24's that are dynamic that have shown other patterns of abuse. Because my server is private, I don't need to be concerned about inadvertently blocking someone.
First, is there a more effective way to block these lists in iptables? Is there a more efficient way to load these large lists of IPs into the chain(s)? At this point, it actually causes my system boot time to lag significantly.
Where is the best place to block these IPs in the chains and why doesn't just blocking it in the INPUT chain work. Or did I configure the DROP incorrectly?
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: BlazPosted on 2009-09-09 at 23:58:43ID: 25297847
Your script looks correct. However you didn't write how you use your abuse chain. I suspect you have a rule like (first rule in INPUT chain):
tore - it is probably faster method to load a large set of rules opposed to issuing iptables command for each rule.
iptables -I INPUT -j abuse
if you want to block FORWARD table also you should add a rule:
iptables -I FORWARD -j abuse
As far as performance issues are concerned:
Do you see problems only at boot time or at packet processing time? If you see processing time issues (network bandwidth drops or load on machine is high when high network traffic is present) I would suggest:
1. make sure that you have rule order as follows:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -j abuse
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
Most traffic will be affected by rule #1 - established traffic. Only new connections will be tested against abuse IPs and against other rules.
2. If you have REALLY large database of IPs it might be better to create more abuse chains:
iptables -A INPUT -j abuse
iptables -A FORWARD -j abuse
...
iptables -A abuse -s 0.0.0.0/3 -j abuse1
iptables -A abuse -s 32.0.0.0/3 -j abuse32
iptables -A abuse -s 64.0.0.0/3 -j abuse64
...
iptables -A abuse1 -s 1.x.x.x -j DROP
iptables -A abuse1 -s 13.y.y.y -j DROP
...
iptables -A abuse32 -s 33.z.z.z -j DROP
...
You create a sort of search tree for IPs by this method - the packet does not need to traverse the whole IP database but only 1/8 of the database but it has one more chain jump. I have not tested this solution because I have never had so large IP lists that I would notice performance problems
If you have problems only at load time you could try iptables-save/iptables-res