From: Pascal Hambourg <pascal.mail@plouf.fr.eu.org>
To: Mauricio Tavares <raubvogel@gmail.com>
Cc: netfilter@vger.kernel.org
Subject: Re: newbie: forward rule to itself
Date: Thu, 28 Oct 2010 10:01:37 +0200 [thread overview]
Message-ID: <4CC92DE1.4030204@plouf.fr.eu.org> (raw)
In-Reply-To: <4CC8774C.1070908@gmail.com>
Hello,
Mauricio Tavares a écrit :
> Let's say I have server1 with two ports, eth0 and eth0, and server2
Did you mean "eth0 and eth1" ?
> whose eth0 port is connected to server1's eth1. And let's say the subnet
> between them is 192.168.1.0/24 while the one server1's eth0 is connected
> to is 192.168.4.0/24.
>
> I have the following rules to forward port 6969 coming on eth0 on
> server1 to port 6969 on server2's eth0:
>
> iptables -A PREROUTING -t nat -p tcp --dport 6969 -j DNAT --to
> 192.168.1.server2:6969
> iptables -A INPUT -d 192.168.4.server1 -p tcp -m tcp -m state --state
> NEW --dport 6969 -j ACCEPT
This rule in INPUT is pointless because
1) packets have already been DNATed by the previous rule in PREROUTING,
2) the new destination is a remote address, so packets go through
FORWARD, not INPUT.
> iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
>
> Any machine in 192.168.4.0/24 seems to be able to get to server2 by
> using 192.168.1.server1:6969. But, if I try to connect to
> 192.168.1.server1:6969 on server1 itself, I will not be forwarded to
> server2. What am I missing here?
As Jan explained, the PREROUTING chain of the 'nat' table sees only
incoming packets received from outside. DNAT for locally generated
packets must be done in the OUTPUT chain.
PS : If you want the connection to work from server2 too, you must add a
specific MASQUERADE/SNAT for it too in POSTROUTING.
prev parent reply other threads:[~2010-10-28 8:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-27 19:02 newbie: forward rule to itself Mauricio Tavares
2010-10-27 19:17 ` Jan Engelhardt
2010-10-27 19:47 ` Mauricio Tavares
2010-10-27 20:00 ` Jan Engelhardt
2010-10-27 21:03 ` Mauricio Tavares
2010-10-28 8:01 ` Pascal Hambourg [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=4CC92DE1.4030204@plouf.fr.eu.org \
--to=pascal.mail@plouf.fr.eu.org \
--cc=netfilter@vger.kernel.org \
--cc=raubvogel@gmail.com \
/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