From: "Rob Sterenborg" <rob@sterenborg.info>
To: 'akshaysalkar' <akshaysalkar@indiatimes.com>,
netfilter@lists.netfilter.org
Subject: RE: iptables forward rulesets woes
Date: Wed, 24 Sep 2003 07:49:19 +0200 [thread overview]
Message-ID: <001c01c3825f$99375470$0401000a@tanjian> (raw)
In-Reply-To: <200309240448.KAA10542@WS0005.indiatimes.com>
> iptables -F FORWARD
> iptables -P FORWARD DROP
> iptables -A FORWARD -m tcp -p tcp -s 0/0 --sport 80 -d
> 172.16.1.0/24 --syn -j DROP
> iptables -A FORWARD -m tcp -p tcp -s 172.16.1.0/24 --sport
> 80 -d 0/0 -j ACCEPT
> iptables -A FORWARD -m tcp -p tcp -d 172.16.1.0/24 --dport
> 80 -s 0/0 -j ACCEPT
>
> i dont kinda understand this...
> firstly 2nd line whats the -P. i guess its the default
> policy. but i could have given as
> iptables -A FORWARD -j DROP
Yes, it's default policy and indeed you could also do that to with -A,
but then it should be your last rule ; you can easily forget to do that
when setting up you rules.
Normally you start with DROPing everything and after that create rules
for packets you want to accept.
See : man iptables and the iptables tutorial
(http://iptables-tutorial.frozentux.net/).
> 2nddly 3rd line why the -j DROP i thought it should be ACCEPT
No. You _don't_ want new incomming connections (--syn) from port 80 to
be forwarded because you didn't initiate them.
I cannot imagine a webserver sending out packets to one of my
workstations by all itself (so I didn't make a request to it) ;-).. Can
you ?
> 3rdly since it says access the WWW servers on the internet
> why is it that on the 4th linethe --sport is 80
> the source doesnt necessarily have to be 80 it could be any
> unprivileged port. the --dport should be infact 80
What they want to do is to let return packets pass, as they don't use
the RELATED,ESTABLISHED states.
But, as you say, a packet is coming FROM 172.16.1.0/24 TO port 80/tcp.
Thus it should be -d.
And in the next line a packet is going TO 172.16.1.0/24 FROM port 80/tcp
thus should be -s as we most likely are not listening on port 80.
I wouldn't do it this way. The state framework is easier to use.
> and the last line also seems confusing to me. where the -d is
> the network-ip
>
> please help me/ suggest.
iptables -F FORWARD
iptables -P FORWARD DROP
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD [-i if_in] -s 172.16.1.0/24 -p tcp --dport 80 -j
ACCEPT
iptables -A FORWARD [-i if_in] -s 172.16.1.0/24 -p tcp --dport 443 -j
ACCEPT
(The part I'm missing here :)
iptables -t nat -A POSTROUTING [-o if_out] -s 172.16.1.0/24 -p tcp
--dport 80 -j SNAT --to-source <ip_ext>
iptables -t nat -A POSTROUTING [-o if_out] -s 172.16.1.0/24 -p tcp
--dport 443 -j SNAT --to-source <ip_ext>
Flush all rules.
Set default policy to DROP.
RELATED,ESTABLISHED will take care of any return packets.
Accept packets to webservers (http and https) in the FORWARD chain.
SNAT packets to webservers in the nat table POSTROUTING chain.
Rob
prev parent reply other threads:[~2003-09-24 5:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-24 5:05 iptables forward rulesets woes akshaysalkar
2003-09-24 5:49 ` Rob Sterenborg [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='001c01c3825f$99375470$0401000a@tanjian' \
--to=rob@sterenborg.info \
--cc=akshaysalkar@indiatimes.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox