IP Tables slows network response times
AS FOLLOWS: (Opps. my mistake!)
root@202-150-101-225:/home/michael# iptables-save # Generated by iptables-save v1.3.3 on Mon Aug 15 23:29:05 2005 *mangle :PREROUTING ACCEPT [26426:1982742] :INPUT ACCEPT [26426:1982742] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [24934:3548792] :POSTROUTING ACCEPT [24934:3548792] COMMIT # Completed on Mon Aug 15 23:29:05 2005 # Generated by iptables-save v1.3.3 on Mon Aug 15 23:29:05 2005 *filter :INPUT DROP [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [24885:3543903] -A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto smtp -m tcp --dport 25 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto dns -m tcp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.225 -p udp -m layer7 --l7proto dns -m udp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.235 -p tcp -m layer7 --l7proto dns -m tcp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.235 -p udp -m layer7 --l7proto dns -m udp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto http -m tcp --dport 80 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m tcp --dport 110 -j ACCEPT -A INPUT -d 202.150.101.226 -p tcp -m tcp --dport 443 -j ACCEPT -A INPUT -d 202.150.101.227 -p tcp -m tcp --dport 443 -j ACCEPT -A INPUT -s 129.223.123.249 -d 202.150.101.225 -p tcp -m tcp --dport 9050 -j ACCEPT -A OUTPUT -o lo -j ACCEPT COMMIT # Completed on Mon Aug 15 23:29:05 2005 root@202-150-101-225:/home/michael#
Michael Hallager
networkStuff ltd
www.networkstuff.co.nz | p.09.839.1000 | m.029.638.7883
Review
Quoted 7 lines · Michael Hallager
AS FOLLOWS: (Opps. my mistake!)
(quoted diff) +0
-5-A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto smtp -m tcp --dport 25 -j ACCEPT
l7filtering is completly useless here. In fact l7 is able to detect a protocol after a few packets so your
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT take precedence over l7 rules.
Furthermore (I may be mistaking) match is often done on reply thus filtering on OUTPUT is necessary.
One other point is : why do you need to check the protocol running on your own computer ?
BR,
Signature · 2 lines
Eric Leblond <[email protected]> INL
Quoted 1 line · Michael Hallager
AS FOLLOWS: (Opps. my mistake!)
Another mistake is that the script ("batch") in the OP would not have generated these rules. Having referred back to that I see you're using the netfilter drivers built-in rather than as modules. A *big* mistake. What is the benefit you expected to see from that choice?
Learn to walk before you try to run. "I have the bare number of needed modules compiled into the custom kernel," you said. But do you know what are really needed? I doubt it.
Quoted 3 lines
root@202-150-101-225:/home/michael# iptables-save # Generated by iptables-save v1.3.3 on Mon Aug 15 23:29:05 2005 *mangle
You (was it you?) compiled in mangle support; you're not using it.
Review
Quoted 9 lines
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [24885:3543903](quoted diff) +0
-3-A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m tcp --dport 22 -j ACCEPT
The destination IP addresses were not in the script posted.
Quoted 2 lines
-A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto smtp -m tcp --dport 25 -j ACCEPT
layer7 was DEFINITELY not mentioned. Is this not only available as a patch? From an unpatched slackware-current install:
# iptables -vA INPUT -m layer7 -l7proto smtp iptables v1.3.3: Couldn't load match `layer7':/usr/lib/iptables/libipt_layer7.so: cannot open shared object file: No such file or directory
Did you not configure this machine yourself? If you did, why did you choose layer7 filtering? And why would you not have considered that a relevant fact in posting your question? Either you deliberately put us through a silly guessing game, or you have no idea what you are doing with your kernel.
Why do we see so many posters who post before RTFM?
Quoted 2 lines
-A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto dns -m tcp --dport 53 -j ACCEPT
Do you even understand what layer7 filtering does? I don't use it myself, nor am I likely to do so in the future, but my high-level understanding is that it inspects the content of each packet against protocol definitions to see if it matches.
It's a fun idea, but it's ugly and slow in practice. No wonder your firewall is slowing things down.
In GNU/Linux, things will mostly work as designed. When you start patching and changing things, be sure you know what you are doing.
In my years of learning and doing I have certainly encountered my fair share of frustration. But as a rule I've found that by leaving things alone until I understand them, I am much more successful.
Dx: severe Clue deficiency
Rx: revert to a Slackware kernel/modules
Rx: RTFM: http://netfilter.org/documentation/
Rx: RTFM: http://slackbook.org/html/
Px: GOOD, if Rx followed; POOR otherwise
Signature · 2 lines
mail to this address is discarded unless "/dev/rob0"
or "not-spam" is in Subject: headerOohps, forgot to send to the list :(
Michael Hallager schrieb:
[SNIP]
Quoted 27 lines
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [24885:3543903](quoted diff) +0
-19-A INPUT -i lo -j ACCEPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto smtp -m tcp --dport 25 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto dns -m tcp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.225 -p udp -m layer7 --l7proto dns -m udp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.235 -p tcp -m layer7 --l7proto dns -m tcp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.235 -p udp -m layer7 --l7proto dns -m udp --dport 53 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m layer7 --l7proto http -m tcp --dport 80 -j ACCEPT -A INPUT -d 202.150.101.225 -p tcp -m tcp --dport 110 -j ACCEPT -A INPUT -d 202.150.101.226 -p tcp -m tcp --dport 443 -j ACCEPT -A INPUT -d 202.150.101.227 -p tcp -m tcp --dport 443 -j ACCEPT -A INPUT -s 129.223.123.249 -d 202.150.101.225 -p tcp -m tcp --dport 9050 -jACCEPT
-A OUTPUT -o lo -j ACCEPT
COMMIT
# Completed on Mon Aug 15 23:29:05 2005
Quoted 1 line
root@202-150-101-225:/home/michael#
Ok, I see. I think your problem is related to L7, 'cause you cannot have a policy of DROP with L7. The following is likely to happen:
1.) You get e.g. an SMTP request == SYN bit set. 2.) As none of your rules match the packet hits the policy,
which is DROP.
3.) L7 is never able to recognize the SMTP protocol.
So I don't think that the network speed is slowed down, I think there is no SMTP, DNS and HTTP connection at all. You have no problem with POP3 and HTTPS, right ?
I would recommend the following:
1.) Move your L7 rules to mangle/PREROUTING *and* mangle/POSTROUTING.
This is because you don't forward the packets. As Eric said, some protocols are recognized in OUTPUT and some in INPUT.
2.) Omit the port with L7. L7 is designed for detecting protocols,
even on non standard ports (well, that's one point :)) You may omit -p too.
3.) Don't rely on L7 in terms of security (you read the HOWTO ?) !! 4.) Filter in filter table. If you really want to filter with L7,
I think it's best, to mark the packets in PREROUTING and and then filter based on the marks in filter table. Only my 2C.
If you don't have the need of recognizing protocols (means: using L7 for convenience), do standard filtering like port matches and so on using connection tracking (so, compile nat into the kernel).
HTH and have a nice time,
Joerg