Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been using snort in conjunction with a firewall that I will list below. This little script takes a whitelist and blacklist and creates my firewall.
The problem is my blacklist has grown to several thousand IP address and ranges. Is there a way to speed things up? Attached is the firewall and I will also list the blacklist. I use the SANS storm watch to add to the block list as well as my own snort logs.
# Go through $WHITELIST, accepting all traffic from the hosts and networks
# contained on that list
#
for x in `grep -v ^# $WHITELIST | awk '{print $1}'`; do
echo "Permitting $x..."
iptables -A INPUT -t filter -s $x -j ACCEPT
done
# Go through $BLACKLIST, blocking all traffice from these hosts and networks
for x in `grep -v ^# $BLACKLIST | awk '{print $1}'`; do
echo "Blocking $x..."
iptables -A INPUT -t filter -s $x -j DROP
done
# Netx the ports will we will accept from non-black list addresses
for port in $ALLOWED; do
echo "Accepting port $port..."
iptables -A INPUT -t filter -p tcp --dport $port -j ACCEPT
done
# Drop anything else not contained in the white list or the ports defined above
iptables -A INPUT -t filter -p tcp --syn -j DROP
One thing that will greatly increase efficiency is to add in connection state tracking:
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Stick that in before your first 'for' loop. By adding this, only the 'first' packet of every connection will be checked against your entire list. With out it, every single packet you receive will have to traverse your entire chain.
Also - I notice that you seem to want to drop anything not on the 'whitelist' If this is so - why check against your "blacklist" at all?
In addition to using connection tracking, you might be able to speed it up by minimizing the number of rules a packet has to be checked against. Here's what I would try - its a lot more maintenance, though:
# create a new chain for every "class A" network on the blacklist
iptables -N TEST_63
iptables -N TEST_64
# if its a new connection, jump for each network
iptables -A INPUT -s 63.0.0.0/8 -m state --state NEW -j TEST_63
iptables -A INPUT -s 64.0.0.0/8 -m state --state NEW -j TEST_64
iptables -A TEST_63 -s 63.139.54.192 -j DROP
iptables -A TEST_63 -s 63.148.99.0/255.255.255.0 -j DROP
iptables -A TEST_64 -s 63.166.2.183 -j DROP
# returns to the next line in the INPUT chain
That way if you have 10 "class A" networks on the black list, each with 10 hosts/subnetworks, rather than parse 100 rules, it would parse the first ten rules, and if it matches, only ten more rules, so a max of 20 rules rather than 100.
Thanks for all the good info. I am going to start working on my script asap. It makes good sense. I love iptables! I also have a netscreen 5fg sitting here, but it won't work with my DSL provider. I use both for an effective DMZ setup.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.