Something I noticed right away...in the second ruleset we have:
Quote:
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
And later:
Quote:
-A INPUT -p tcp -m state --state NEW --dport 30000 -j ACCEPT
The oversight here is that after the ESTABLISHED,RELATED rule, the only packets moving forward are NEW and INVALID. For every SSH connection, the ruleset is needlessly checking the state, as it's only going to be NEW or INVALID (and you should have a rule to drop INVALID anyway). The method with which I preamble my iptables ruleset is as follows:
Code:
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -m state --state INVALID -j DROP
After those two rules every packet will be NEW (for TCP, a SYN). I'm not the biggest fan of rejecting unexpected traffic, either; I know it's
The Right Thing to do, but in a DDoS situation you're going to be compounding the problem with the rejection packets.
Another thing that
really bothers me is blind rejection of all ICMP packets except for type 8. Particularly for IPv6, ICMP serves a lot of uses that naive administrators overlook by dropping them all.
A good rule of thumb to keep in mind when you're dealing with Netfilter is that your most popular traffic should have a decision made on it as soon as possible, to decrease overhead. Another important means of decreasing overhead is doing as few compares as possible before a decision is made. Your most popular traffic is almost always RELATED,ESTABLISHED and that should be the first rule in the table. In these rulesets, the loopback rules are first...which means that for every active connection, you're doing a compare against loopback for every packet, which is a waste of overhead.
The first ruleset doesn't fare much better there, as ESTABLISHED,RELATED is pushed 5 rules down.
Another problem I noticed with both rulesets it that each author adds a rule to the end of INPUT and OUTPUT, without even addressing the chain's policy itself. Every chain has a default policy which, when packets run off the end, gets used (including a friendly counter on the top). For example, to set default DROP on everything:
Code:
-P INPUT DROP
-P OUTPUT DROP
-P FORWARD DROP
...yet, these authors add a pointless rule to do the same thing.
I don't like either ruleset (because each strikes me as written by someone not very conscious of Netfilter's workings), and my advice to you would be to play with the rulesets themselves on a non-production box. Verbosely log your traffic at various spots in the chains and see what does what. That's how I taught myself iptables (I didn't adopt Linux early enough to get into ipchains, its predecessor), and once it
clicks, it's not that bad.
Edit: Oh, forgot to add -- you can look at something like
Shorewall, and see how it writes rules.