Help on iptables setting on forwarding

This is a discussion on Help on iptables setting on forwarding within the Linux Security forums, part of the System Security and Security Related category; Hi, I set up my Linux box for IP Masquerading according to "how-to". I used iptables settings ...


Go Back   Usenet Forums > System Security and Security Related > Linux Security

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-23-2003
Alan
 
Posts: n/a
Default Help on iptables setting on forwarding

Hi,
I set up my Linux box for IP Masquerading according to "how-to". I used
iptables settings accordingly to the strong firewall rulesets. The
suggested rulesets allow all traffic to be masqueraded from the internal
interface. Please suggest rulesets on allowing ONLY port 80 and pert 443
to be forwarded from the internal interface.

I tried to modify:

$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -p tcp --dport 80 -j ACCEPT

but it did not work.

Thanks.

Regards
Alan

Reply With Quote
  #2 (permalink)  
Old 10-23-2003
Stephen Webster
 
Posts: n/a
Default Re: Help on iptables setting on forwarding

Alan wrote:
[snip]
> suggested rulesets allow all traffic to be masqueraded from the internal
> interface. Please suggest rulesets on allowing ONLY port 80 and pert 443
> to be forwarded from the internal interface.
>
> I tried to modify:
>
> $IPTABLES -A FORWARD -i $INTIF -o $EXTIF -p tcp --dport 80 -j ACCEPT
>
> but it did not work.
>


Without seeing the rest of your script I'd guess that you're not
allowing the packets returning from the destination web server through.
Try something like the following:

$IPTABLES -A FORWARD -p TCP -i $INTIF -o $EXTIF --dport 80 -m state
--state NEW,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -p TCP -i $EXTIF -o $INTIF --sport 80 -m state
--state ESTABLISHED -j ACCEPT

The above should be 2 iptables commands, sorry if my newsreader has
broken the lines strangley.

--
Steve Webster
Remove the 'nospam' to get my email address.

Reply With Quote
  #3 (permalink)  
Old 10-23-2003
Peter Eberz
 
Posts: n/a
Default Re: Help on iptables setting on forwarding

Hello,
I think you need the folloing entries in your NAT table.
The first rule forwards the incoming packets to the HTTP server.
The second rule allows you access to the HTTP server from the inside using
your externel IP address.

$IPTABLES -t nat -A PREROUTING -p TCP -i $EXTIF -d $EXTIP --dport 80 \
-j DNAT --to-destination $DMZ_HTTP_IP
$IPTABLES -t nat -A PREROUTING -p TCP -i $INTIF -d $EXTIP --dport 80 \
-j DNAT --to-destination $DMZ_HTTP_IP

$IPTABLES -t nat -A PREROUTING -p TCP -i $EXTIF -d $EXTIP --dport 443 \
-j DNAT --to-destination $DMZ_HTTP_IP
$IPTABLES -t nat -A PREROUTING -p TCP -i $INTIF -d $EXTIP --dport 443 \
-j DNAT --to-destination $DMZ_HTTP_IP

Additionally you will the following forwarding rules. If you do not have
your HTTP server in a DMZ you only need two rules and you have to replace
the $DMZIF with your $INTIF.

$IPTABLES -A FORWARD -p TCP -i $EXTIF -o $DMZIF -d $DMZ_HTTP_IP \
--dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -p TCP -i $DMZIF -o $EXTIF --sport 80 \
-m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -p TCP -i $INTIF -o $DMZIF -d $DMZ_HTTP_IP \
--dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -p TCP -i $DMZIF -o $INTIF --sport 80 \
-m state --state ESTABLISHED,RELATED -j ACCEPT

I think the rules for HTTPS you can figure out yourself.

Bye,
Peter

On Thu, 23 Oct 2003 08:29:07 +0800, Alan wrote:

> Hi,
> I set up my Linux box for IP Masquerading according to "how-to". I used
> iptables settings accordingly to the strong firewall rulesets. The
> suggested rulesets allow all traffic to be masqueraded from the internal
> interface. Please suggest rulesets on allowing ONLY port 80 and pert 443
> to be forwarded from the internal interface.
>
> I tried to modify:
>
> $IPTABLES -A FORWARD -i $INTIF -o $EXTIF -p tcp --dport 80 -j ACCEPT
>
> but it did not work.
>
> Thanks.
>
> Regards
> Alan


Reply With Quote
  #4 (permalink)  
Old 10-25-2003
Bryan Packer
 
Posts: n/a
Default Re: Help on iptables setting on forwarding

Peter Eberz wrote:

> Hello,
> I think you need the folloing entries in your NAT table.
> The first rule forwards the incoming packets to the HTTP server.
> The second rule allows you access to the HTTP server from the inside using
> your externel IP address.
>
> $IPTABLES -t nat -A PREROUTING -p TCP -i $EXTIF -d $EXTIP --dport 80 \
> -j DNAT --to-destination $DMZ_HTTP_IP
> $IPTABLES -t nat -A PREROUTING -p TCP -i $INTIF -d $EXTIP --dport 80 \
> -j DNAT --to-destination $DMZ_HTTP_IP
>
> $IPTABLES -t nat -A PREROUTING -p TCP -i $EXTIF -d $EXTIP --dport 443 \
> -j DNAT --to-destination $DMZ_HTTP_IP
> $IPTABLES -t nat -A PREROUTING -p TCP -i $INTIF -d $EXTIP --dport 443 \
> -j DNAT --to-destination $DMZ_HTTP_IP


These would be rules if the OP were running a webserver in a DMZ. I think he was
trying to limit outbound traffic from his LAN to only HTTP and HTTPS. *Assuming*
that is the case, all a person needs is:

Make sure your FORWARD chain has a default policy of DROP or REJECT so only
add in 2 rules to traffic you want is alowed to leave, then allow the
outbound packets:

$IPTABLES -A FORWARD -p tcp -o $EXTIF -s $LAN --dport 80 -j ACCEPT
$IPTABLES -A FORWARD -p tcp -o $EXTIF -s $LAN --dport 443 -j ACCEPT

Add a rule to NAT the packets. No need to write bunches of rules specifying
only specific ports to be NAT'd since the FORWARD chain won't be allowing
any outbound packets to any other ports anyway. That way when he discovers that
he needs to allow a few more ports, which will happen at some point, all he
needs to do is add a single rule to the FORWARD chain and it's fixed.

$IPTABLES -t nat -A PREROUTING -p tcp -i $INTIF -d $EXTIP -s $LAN --dport 80 \
-j SNAT --to $EXTIF

Then allow all related packets back in. Again, writing bunches of rules to allow
each type of traffic back in just wastes CPU. If your outbound rules are solid,
there can't be any other RELATED or ESTABLISHED packets coming back except those
which you expressly allowed out.

$IPTABLES -A FORWARD -p tcp -i $EXTIF -o $INTIF -d $LAN \
-m state --state ESTABLISHED,RELATED -j ACCEPT

bryan

--
A Freudian slip is when you say one thing but mean your mother.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:45 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0