From: Grant Taylor <gtaylor@riverviewtech.net>
To: Mail List - Netfilter <netfilter@vger.kernel.org>
Subject: Re: SNAT
Date: Tue, 09 Oct 2007 14:47:16 -0500 [thread overview]
Message-ID: <470BDAC4.9020206@riverviewtech.net> (raw)
In-Reply-To: <470BCCC7.2070007@corp.web.com>
On 10/09/07 13:47, Chad Eldridge wrote:
> I have a situation where I have packets coming into a server (we'll
> call it RTR) and getting routed to other servers depending on the ip
> address the packet is coming from. This part works great. The problem
> I am having is when the server (call it Responder) answers back to
> the original client (not going back through RTR), the client sees the
> traffic coming from an address it did not originally try to open a
> connection to and therefore rejects the packets and the connection is
> never established. I thought I could fix this by using SNAT to change
> the source ip on Responder.
>
> iptables -t nat -A POSTROUTING -p tcp -m tcp --sport $PORT -j SNAT
> --to $RTR-IP
Ah, you are falling victim to what I consider a communications triangle.
You are describing exactly what happens. A connects to B, B redirects
to C, C responds to A, and A is rather distraught that B is ignoring him
/ her while this yahoo C is not using proper protocol / grammar to start
a conversation.
> This however, seems to do nothing. The Responder still sends replies
> to the client, they make it to the client and show up as coming from
> the ip address of Responder.
Where did you try to SNAT? Were you trying to SNAT on RTR to make the
Responder think the traffic came from RTR or were you trying to SNAT on
the Responder to make the traffic to the client look like it came from
RTR? I'm guessing the second method seeing as how the first should have
worked (and has for me). I suppose that if you could get the source IP
of the traffic from Responder to really be that of RTR things would work
too, but I'm not sure what type of reverse path issues you will have /
need to over come.
> It was suggested to me that I would need to turn off rp_filter (echo
> 0 /proc/sys/net/ipv4/conf/all/rp_filter; echo 0
> /proc/sys/net/ipv4/conf/eth0/rp_filter) since the ip address I am
> trying to change the source to does not actually exist on the server.
> I tried that but it did not seem to help. Further more it was
> suggested that I could setup the $RTR-IP on a loopback and arptables
> it off and then it should work. This did not work either. If it is
> because iptables is trying to prevent spoofing I'm guessing it is
> stopping it because it's trying to send it out an interface that does
> not have the ip on it. Then again, all of this guessing could be
> wrong.
Well to start with, you do not want to use the loop back interface
because the kernel will protect it at all costs. In short, the only
thing that can communicate with the loop back device is the loop back
device its self. Any and all attempts that I'm aware of to over come
this short of an application layer proxy that binds to loop back and
other interfaces will most likely fail with out some kernel patching.
I feel like I just answered a similar question with in the last week or
so. I think that question had to do with pseudo load balancing though.
However the answer to that question fits here too.
> Is this even possible with iptables? If so, how can I accomplish it?
> Everything I have seen that seems like it should work has so far
> failed.
I'm not sure if IPTables can solve this its self or not. You may need
some help from bridging and EBTables.
I have to ask, are the responders hidden behind the router? I'm
guessing now because it sounds like the responder is talking directly
back to the client. Thus are the router and responders in the same
subnet / broadcast domain? For the sake of conversation I'm going to
presume the latter. So let's have some ASCII art to help explain this.
+------------+
| Default GW |
+-----+------+
|
+------------+-----+------+------------+
| | | |
+---+----+ +---+----+ +---+----+ +---+----+
| Router | | Host A | | Host B | | Host C |
+--------+ +--------+ +--------+ +--------+
Let's presume for the sake of conversation that a client connects in to
Router from the internet. Router decides to redirect the traffic to
Host A based on the source IP address. At the same time a different
client connects in to Router from the internet. However this second
client is from a different IP address and as such Router decides to
redirect the traffic to Host C.
Router and Hosts A, B, and C, all need to have the same IP bound to an
interface that will allow non localhost communications to them (read:
not loop back). Hosts A, B, and C need to NOT respond to ARPs from
Default GW to find the IP in question so that you can be sure that
Router will respond and be found. Thus Default GW will send the packets
destined to the target IP to Router. Router will then need to redirect
the packets over to Host A or B or C as it sees fit. Hosts A, B, and C
will then receive the packet and process the request and respond in kind
back out Default GW. This way, the original client will see the correct
source IP on the reply traffic.
Using EBTables Router can alter the destination MAC address the packets
coming in based on the source IP. Thus you can use EBTables to redirect
some traffic to Host and some to Host B and some to Host C as you see fit.
You may need to have multiple IP addresses bound to the network
interfaces of Hosts A, B, and C so that they respond from the correct
source IP while using Default GW on a different subnet so that Default
GW does not update it's ARP cache with the new MAC addresses of Host A
or B or C.
At least as I understand it, this is how one mode of LVS operates. This
will also work for what you are wanting to do.
> iptables v1.2.8
> Redhat ES3
> (Final box will probably be running ES4)
As long as you include EBTables and / or LVS in the mix I don't think
the difference between ES3 and ES4 will matter.
> Thanks,
*nod*
Good luck.
Grant. . . .
next prev parent reply other threads:[~2007-10-09 19:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-09 18:47 SNAT Chad Eldridge
2007-10-09 19:47 ` Grant Taylor [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-02-22 2:04 SNAT cc
2012-02-22 7:47 ` SNAT SamLT
2005-05-02 15:32 snat Marco Berizzi
2005-05-02 15:53 ` snat Jason Opperisano
2005-05-03 13:58 ` snat Marco Berizzi
2005-05-02 16:07 ` snat Taylor, Grant
2005-05-02 16:14 ` snat Jason Opperisano
2005-05-02 2:52 ` snat Ken Hilliard
2005-05-02 18:04 ` snat Charlie Brady
2005-05-02 18:06 ` snat Jason Opperisano
2005-05-02 3:14 ` snat Ken Hilliard
2004-07-09 3:57 SNAT Payal Rathod
2004-07-09 4:58 ` SNAT John A. Sullivan III
2003-07-08 0:21 SNAT David Busby
2003-04-25 17:45 SNAT Andy Wood
2003-04-03 18:34 SNAT Daniel Chemko
2003-04-06 10:52 ` SNAT Rio Martin.
2003-04-06 21:49 ` SNAT Daniel Chemko
[not found] <20030403102302.5858.91445.Mailman@kashyyyk>
2003-04-03 10:29 ` SNAT Rio Martin.
2002-11-13 11:21 SNAT Rob Sterenborg
2002-11-13 13:26 ` SNAT Breno Cardoso Perucchi
2002-11-13 13:48 ` SNAT Rob Sterenborg
2002-11-13 16:33 ` SNAT Luis Fernando Barrera
2002-11-12 18:38 MS Messenger Aaron Clausen
2002-11-12 19:53 ` SNAT Breno Cardoso Perucchi
2002-11-12 21:01 ` SNAT Rob Sterenborg
2002-11-12 21:29 ` SNAT Antony Stone
2002-11-12 21:47 ` SNAT Luis Fernando Barrera
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=470BDAC4.9020206@riverviewtech.net \
--to=gtaylor@riverviewtech.net \
--cc=gtaylor+reply@riverviewtech.net \
--cc=netfilter@vger.kernel.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 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.