From: James Sneeringer <james+netfilter@vincentsystems.com>
To: netfilter@lists.netfilter.org
Subject: Re: Firewall structure and more (Newbie)
Date: Thu, 8 Jul 2004 12:47:16 -0500 [thread overview]
Message-ID: <20040708174716.GC28733@valjean.si.ocslink.com> (raw)
In-Reply-To: <20040708171016.GA16115@itstud.chalmers.se>
On Thu, Jul 08, 2004 at 07:10:16PM +0200, Erik Wikstr?m wrote:
> My idea is to create 3 chains for each scenario, one for tcp, one for
> udp and one for icmp. And maybe some more like one for port forwarding
> or so. But that's an awful lot of rules and some of them might contain
> only one or two rules
How you structure your rules and chains is entirely up to you, and depends
on your specific needs. However, in general you should set up your rules
and chains so the kernel has to do as little work as possible. Sometimes
this isn't possible, but in practice, you can usually break up large chains
into smaller ones. For example, this isn't a long chain, but it illustrates
the point.
iptables -A FORWARD -p tcp -s 10.0.0.2 --dport 80 -j ACCEPT
iptables -A FORWARD -p tcp -s 10.0.0.2 --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp -s 10.0.0.2 --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp -s 10.0.0.3 --dport 80 -j ACCEPT
iptables -A FORWARD -p tcp -s 10.0.0.3 --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp -s 10.0.0.3 --dport 110 -j ACCEPT
Instead, you might do something like this:
iptables -N CHECK_PORTS
iptables -A FORWARD -s 10.0.0.2 -j CHECK_PORTS
iptables -A FORWARD -s 10.0.0.3 -j CHECK_PORTS
iptables -A CHECK_PORTS -p tcp --dport 80 -j ACCEPT
iptables -A CHECK_PORTS -p tcp --dport 25 -j ACCEPT
iptables -A CHECK_PORTS -p tcp --dport 110 -j ACCEPT
iptables -A CHECK_PORTS -j RETURN
For a case where 10.0.0.3 wants to go to port 25, the first set of rules
requires the kernel to evaluate 5 rules. The second example only requires
evaluation of 3 rules. It's also a bit more modular and makes it simpler
to grant the same access to another IP in the future.
> Which leads to my questions: What do you think of this structure? What
> would you do?
>
> How many rules should there be in a chain to compensate for the chain?
> (Cause there are some overhead for each chain right?)
Unless you're doing this on a 386 with 4 MB RAM, the overhead of each
individual chain isn't worth worrying about.
> I'm also open to suggestions for things to block, and maybe suggestions
> on rules to do so, like ping of death and other known problems.
Personally, I use the state module, and I block all inbound traffic by
default. The only permitted inbound traffic is stuff that matches state
ESTABLISHED,RELATED, and thinks like tcp/25 to my mail server. For what
ut's worth, I have no custom chains on my firewall (486dx2/66, 32 MB RAM).
My FORWARD chain has about 60 rules in it, and performance is just fine.
-James
prev parent reply other threads:[~2004-07-08 17:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-08 17:10 Firewall structure and more (Newbie) Erik Wikström
2004-07-08 17:28 ` Antony Stone
2004-07-08 18:07 ` Erik Wikström
2004-07-08 18:16 ` Antony Stone
2004-07-08 17:47 ` James Sneeringer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040708174716.GC28733@valjean.si.ocslink.com \
--to=james+netfilter@vincentsystems.com \
--cc=netfilter@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.