Skip to contentSkip to conversation

Question on PREROUTING and INPUT chains

DISCUSSION Simon Kowallik 3 participants 3 messages Nov 9, 2002 – Nov 11, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 27 lines · Antony Stone
Quoted 14 lines · Carlos FaÄ¿anha

I have a Linux box used as NAT server and firewall. All requests on its port 80 are forwarded to a local webserver inside my network. I want to block access to all services including http from a specific external host.

I'm using the following rule to block the host

iptables -A INPUT -i $extint -s $hostip -j DROP

and this one to do the NAT

iptables -t nat -A PREROUTING -p tcp --dport 80 -d $extip -j DNAT --to $webserverip:80

Quoted 8 lines

The problem is that the host is blocked from accessing all services but http. I've already checked if there are any rules before that ACCEPT the request. It seems that prerouted packets are bypassing the INPUT chain.

Is it correct? If not, what am I doing wrong?

Quoted 8 lines

It is correct that routed packets bypass the INPUT chain. Only packets destined for the firewall machien go through INPUT - packets which are going somewhere else go through FORWARD.

Therefore put your blocking rule in the FORWARD chain instead and it should do what you want.

Antony.

Perhaps this helps to better understand the "flow":
http://offlineprovider.de/site/netfilter/netfilter.php

Regards,
Simon

#1 lore raw
Quoted 5 lines · Simon Kowallik

Perhaps this helps to better understand the "flow":
http://offlineprovider.de/site/netfilter/netfilter.php

Regards,
Simon

If I'm understanding the diagram correctly that might explain my problems. Am I to understand that all packets on a NAT'ed connection never go through the FORWARD chain of filter?

Is there a pointer to a ChangeLog for netfilter behaviour between 2.4.17 and 2.4.18?

Signature · 2 lines
alex <[email protected]>
My own hacking haven
#2 lore raw
Quoted 10 lines · alex
Quoted 5 lines · Simon Kowallik

Perhaps this helps to better understand the "flow":
http://offlineprovider.de/site/netfilter/netfilter.php

Regards,
Simon

If I'm understanding the diagram correctly that might explain my problems. Am I to understand that all packets on a NAT'ed connection never go through the FORWARD chain of filter?

No, that is not correct.

ALL packets which get routed through a netfilter box go through the FORWARD filter chain.

Packets coming in to a netfilter box (and either terminating there, or going through it to some other destination) go through the PREROUTING nat table.

Packets leaving a netfilter box (whether they came through it from somewhere else, or originated on the box) go through the POSTROUTING nat table.

The only thing which normally catches people out is that reply packets which are part of a NATted connection do not go through the rules in the nat tables
- they get "automagically reverse NATted" in the correct way to match the NAT of the original packets (to which these are replies), which *was* done by a rule in the tables.

Basically what I'm saying is that you only need to specify nat rules for the first packet in a connection - you don't need to worry about writing your own rule to nat the reply.

Hope this helps.

Antony.

Signature · 2 lines
I vote "no" to this proposal to form a committee to investigate whether we 
should or should not hold a ballot on whether to vote yet.