All of lore.kernel.org
 help / color / mirror / Atom feed
* portfw on iptables 2.4 kernel problem.
@ 2002-12-10  8:56 louie miranda
  2002-12-10  9:01 ` Raymond Leach
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: louie miranda @ 2002-12-10  8:56 UTC (permalink / raw)
  To: netfilter

I have an internel ftp server w/c i want to access over my linux router(gw)
Its internel IP is 10.0.0.11 and port 21. My externel IP lets say
203.100.100.1.
I followed the docs w/c i found at linuxdoc
http://www.tldp.org/HOWTO/IP-Masquerade-HOWTO/forwarders.html
I type in this iptables rule set,

iptables -A FORWARD -i eth0 -o eth1 -p tcp --dport 21 -m state --state
NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A PREROUTING -t nat -p tcp -d $EXTIP --dport 21 -j DNAT --to
10.0.0.11:21

I enabled ip forwarding thru the kernel by typing this command, (this is the
first thing i type then the iptables rule set)

echo "1" > /proc/sys/net/ipv4/ip_forward

svr:/# cat /proc/sys/net/ipv4/ip_forward
1
svr:/#

And still it does not work..

Trying 203.100.100.1...
telnet: Unable to connect to remote host: Connection refused





--
thanks,
louie miranda




^ permalink raw reply	[flat|nested] 24+ messages in thread
[parent not found: <FD8F124A387AD6119F7900A0D218B321561982@hslex01.hslbz.local>]
* RE: portfw on iptables 2.4 kernel problem.
@ 2002-12-11  7:32 Reckhard, Tobias
  2002-12-11  8:05 ` Joel Newkirk
  0 siblings, 1 reply; 24+ messages in thread
From: Reckhard, Tobias @ 2002-12-11  7:32 UTC (permalink / raw)
  To: netfilter

Hi

I'm not entirely sure what you want to do, but here goes.

> I have an internel ftp server w/c i want to access over my 
> linux router(gw)
> Its internel IP is 10.0.0.11 and port 21. My externel IP lets say
> 203.100.100.1.
> I followed the docs w/c i found at linuxdoc
> http://www.tldp.org/HOWTO/IP-Masquerade-HOWTO/forwarders.html
> I type in this iptables rule set,
> 
> iptables -A FORWARD -i eth0 -o eth1 -p tcp --dport 21 -m state --state
> NEW,ESTABLISHED,RELATED -j ACCEPT
> iptables -A PREROUTING -t nat -p tcp -d $EXTIP --dport 21 -j DNAT --to
> 10.0.0.11:21
> 
> I enabled ip forwarding thru the kernel by typing this 
> command, (this is the
> first thing i type then the iptables rule set)
> 
> echo "1" > /proc/sys/net/ipv4/ip_forward
> 
> svr:/# cat /proc/sys/net/ipv4/ip_forward
> 1
> svr:/#
> 
> And still it does not work..
> 
> Trying 203.100.100.1...
> telnet: Unable to connect to remote host: Connection refused

I expect you're trying to access the FTP server on 10.0.0.11 from the
Internet by redirecting connections to the firewall's external IP address
(203.100.100.1) to the FTP server.

I haven't dealt with D/SNATing FTP yet and it's one of the more complicated
protocols to do this for (and it's a horrible protocol anyway, so you should
avoid it entirely if you can), but I believe you need to do the following:

Prerequisites:
1. Load the FTP conntrack and FTP NAT modules (maybe the basic conntrack
module as well), enable IP forwarding.

Take care of the FTP control connection:
2. Permit INPUT on the outside interface of the firewall to TCP port 21 with
states NEW and ESTABLISHED
3. Permit OUTPUT on the outside interface of the firewall from TCP port 21
with state ESTABLISHED
4. In the PREROUTING chain use DNAT to redirect packets "-p tcp -d
203.100.100.1 --dport 21" (see point 2 above) to the internal server at
10.0.0.11.
5. Permit FORWARDing of those same packets with states NEW and ESTABLISHED.
6. Permit FORWARDing of response packets ("-s 10.0.0.11 --sport 21") with
state ESTABLISHED.

The FTP data connection:
a) Active FTP:
7. Permit FORWARDing from the internal server, TCP source port 20, with
states ESTABLISHED and RELATED.
8. Permit FORWARDing to the internal server, TCP destination port 20, with
state ESTABLISHED.
9. Permit OUTPUT from the firewall's outside interface (and source IP
address), TCP source port 20, with states ESTABLISHED and RELATED.
10. Permit INPUT on the firewall's outside interface (and IP), TCP
destination port 20, state ESTABLISHED.

You may also need to SNAT the outbound packets to the firewall's outside IP
address in the POSTROUTING chain.

b) Passive FTP:
11. Permit INPUT on the firewall's outside interface (and IP), TCP
destination port 1024-65535, states ESTABLISHED and RELATED
12. PREROUTING DNAT those packets to the internal server.
13. FORWARD them with states ESTABLISHED and RELATED
14. FORWARD the ESTABLISHED return packets
15. OUTPUT the ESTABLISHED return packets.

Check to see if that works. Add a catch-all logging rule to the end of all
chains you use and see if it gets hit by anything when debugging.

Cheers
Tobias


^ permalink raw reply	[flat|nested] 24+ messages in thread
* RE: portfw on iptables 2.4 kernel problem.
@ 2002-12-11  9:00 Reckhard, Tobias
  2002-12-11 14:25 ` Joel Newkirk
  0 siblings, 1 reply; 24+ messages in thread
From: Reckhard, Tobias @ 2002-12-11  9:00 UTC (permalink / raw)
  To: netfilter

Munging both replies into one, my answers are inline.

> > I expect you're trying to access the FTP server on 
> 10.0.0.11 from the
> > Internet by redirecting connections to the firewall's external IP
> > address (203.100.100.1) to the FTP server.
> 
> > Take care of the FTP control connection:
> > 2. Permit INPUT on the outside interface of the firewall to TCP port
> > 21 with states NEW and ESTABLISHED
> > 3. Permit OUTPUT on the outside interface of the firewall from TCP
> > port 21 with state ESTABLISHED
> > 4. In the PREROUTING chain use DNAT to redirect packets "-p tcp -d
> > 203.100.100.1 --dport 21" (see point 2 above) to the internal server
> > at 10.0.0.11.
> > 5. Permit FORWARDing of those same packets with states NEW and
> > ESTABLISHED. 6. Permit FORWARDing of response packets ("-s 10.0.0.11
> > --sport 21") with state ESTABLISHED.
> 
> This wouldn't work at all.  INPUT shouldn't enter into it at 
> all, unless 
> the DNAT fails, and OUTPUT only if a packet is required to leave the 
> firewall machine itself, IE if that is where the connection 
> is attempted 
> from or to.

The above takes care of the control connection only. Since the Internet
machine believes it is accessing an FTP server on the firewall itself, the
latter is addressed by its FTP control connection. This means that the
packets cross the firewall's INPUT chain, before they can be DNATed in the
PREROUTING chain. I'm not entirely sure about the outbound packets, but most
things netfilter apart from NAT require symmetric rules, so I suppose you
need an OUTPUT rule to match the INPUT one.

[FTP data]

Thanks for the info, but I know all about FTP data.. What did you think
steps 7 through 15 in my recipe were for?

Tobias


^ permalink raw reply	[flat|nested] 24+ messages in thread
* RE: portfw on iptables 2.4 kernel problem.
@ 2002-12-12  7:31 Reckhard, Tobias
  0 siblings, 0 replies; 24+ messages in thread
From: Reckhard, Tobias @ 2002-12-12  7:31 UTC (permalink / raw)
  To: netfilter

[snip]
> > The above takes care of the control connection only. Since the
> > Internet machine believes it is accessing an FTP server on the
> > firewall itself, the latter is addressed by its FTP control
> > connection. This means that the packets cross the firewall's INPUT
> > chain, before they can be DNATed in the PREROUTING chain. I'm not
> > entirely sure about the outbound packets, but most things netfilter
> > apart from NAT require symmetric rules, so I suppose you need an
> > OUTPUT rule to match the INPUT one.
> 
> I don't see how this would be.  The first chain that a packet 
> entering 
> the firewall hits is mangle-PREROUTING, second is nat-PREROUTING.  At 
> that point it is DNATted, and then hits a routing decision that 
> determines if it is local or not, IE INPUT or FORWARD.  It 
> should never 
> 'cross' INPUT at all, unless my understanding (and most sources I've 
> read, and traversal tests performed) is faulty.

Then that's where our impression differs. I have thought up to now that
INPUT is hit before PREROUTING before FORWARD before POSTROUTING before
OUTPUT. And that a packet may stop being processed between PREROUTING and
FORWARD as well as between POSTROUTING and OUTPUT.

I may check the one NATing firewall I have running.. later.

Cheers,
Tobias


^ permalink raw reply	[flat|nested] 24+ messages in thread
* RE: portfw on iptables 2.4 kernel problem.
@ 2002-12-12  7:33 Reckhard, Tobias
  0 siblings, 0 replies; 24+ messages in thread
From: Reckhard, Tobias @ 2002-12-12  7:33 UTC (permalink / raw)
  To: netfilter

> Thanks for those people who replied, But still i can't get it to work.
> Ill be posting my rule set here.

Have you tried the more complicated rule set that I'd posted (in
pseudo-code)? At a first, casual glance, your NAT rules don't look good to
me.

Cheers,
Tobias


^ permalink raw reply	[flat|nested] 24+ messages in thread
* RE: portfw on iptables 2.4 kernel problem.
@ 2002-12-12  8:09 Reckhard, Tobias
  0 siblings, 0 replies; 24+ messages in thread
From: Reckhard, Tobias @ 2002-12-12  8:09 UTC (permalink / raw)
  To: netfilter

Following up to myself...

> Then that's where our impression differs. I have thought up 
> to now that
> INPUT is hit before PREROUTING before FORWARD before 
> POSTROUTING before
> OUTPUT. And that a packet may stop being processed between 
> PREROUTING and
> FORWARD as well as between POSTROUTING and OUTPUT.
> 
> I may check the one NATing firewall I have running.. later.

I just did check that machine and you're right, I was wrong. So INPUT and
OUTPUT rules shouldn't be required in the case we're discussing.

Cheers,
Tobias


^ permalink raw reply	[flat|nested] 24+ messages in thread
[parent not found: <96C102324EF9D411A49500306E06C8D1021AE462@eketsv02.cubis.de >]

end of thread, other threads:[~2002-12-12 14:25 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-10  8:56 portfw on iptables 2.4 kernel problem louie miranda
2002-12-10  9:01 ` Raymond Leach
2002-12-10  9:11   ` louie miranda
2002-12-10  9:01 ` Paulo Andre
2002-12-10  9:12   ` louie miranda
2002-12-11 11:26 ` Andrea Rossato
2002-12-12  3:11   ` louie miranda
     [not found] <FD8F124A387AD6119F7900A0D218B321561982@hslex01.hslbz.local>
2002-12-10  9:43 ` Rob Sterenborg
2002-12-10 11:00   ` Raymond Leach
2002-12-10 11:22     ` Jozsef Kadlecsik
2002-12-10 11:32       ` Raymond Leach
2002-12-10 11:52         ` Jozsef Kadlecsik
2002-12-10 12:12           ` Raymond Leach
2002-12-11  6:08       ` louie miranda
2002-12-11  6:20         ` Raymond Leach
  -- strict thread matches above, loose matches on Subject: below --
2002-12-11  7:32 Reckhard, Tobias
2002-12-11  8:05 ` Joel Newkirk
2002-12-11  9:00 Reckhard, Tobias
2002-12-11 14:25 ` Joel Newkirk
2002-12-12  7:31 Reckhard, Tobias
2002-12-12  7:33 Reckhard, Tobias
2002-12-12  8:09 Reckhard, Tobias
     [not found] <96C102324EF9D411A49500306E06C8D1021AE462@eketsv02.cubis.de >
2002-12-12  8:51 ` Rasmus Reinholdt Nielsen
2002-12-12 14:25   ` Joel Newkirk

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.