All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: snat to multiple source ip
@ 2005-09-20 15:07 Derick Anderson
  2005-09-20 15:16 ` Marco Berizzi
  2005-09-20 15:24 ` Edmundo Carmona
  0 siblings, 2 replies; 17+ messages in thread
From: Derick Anderson @ 2005-09-20 15:07 UTC (permalink / raw)
  To: netfilter

 

> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org 
> [mailto:netfilter-bounces@lists.netfilter.org] On Behalf Of 
> Marco Berizzi
> Sent: Tuesday, September 20, 2005 10:24 AM
> To: netfilter@lists.netfilter.org
> Subject: Re: snat to multiple source ip
> 
> /dev/rob0 wrote:
> 
> > On Tuesday 20 September 2005 07:39, Marco Berizzi wrote:
> 
> > the source IP is set by
> > iproute2 in the routing tables.
> 
> Ok, I'm not clearly explained.
> I'm using SNAT to change the source ip address because 
> iproute2 set an ip address that I don't like.
> So, I have inserted the following line in my firewall script:
> 
> iptables -t nat -I POSTROUTING -s iproute2_chosen_ip 
> --protocol tcp -j SNAT --to i_want_this_first_ip --to 
> i_want_this_second_ip
> 
> But everytime I connect to the internet always 
> "i_want_this_first_ip" is chosen to do the SNAT.

Uneducated, lazy guess: the SNAT target supports only one "--to [IP]"
and the command parser ignores the extraneous "--to [IP2]". You can test
this by switching the two IPs and see if you go out on a different
address.

Derick Anderson


^ permalink raw reply	[flat|nested] 17+ messages in thread
* snat to multiple source ip
@ 2005-09-26 15:38 Marco Berizzi
  2005-09-26 16:10 ` Phil Oester
  0 siblings, 1 reply; 17+ messages in thread
From: Marco Berizzi @ 2005-09-26 15:38 UTC (permalink / raw)
  To: netfilter-devel

Hello everybody.
I would like to better understand the SNAT target when
multiple --to-source are specified.

Man states:

"You can add several --to-source option. If you specify
more than one source address, either via an address range
or multiple --to-source options, a simple round-robin  (one
after another in cycle) takes place between these addresses."

iptables -t nat -I POSTROUTING -s ipX --protocol tcp
-j SNAT --to first_ip --to second_ip

This round robin cycle is per socket. Correct?

But, after a little test, I have concluded that SNAT
choose the second IP when the system open a second
socket to the same host.

SNAT test results:

1st socket opened to a.a.a.a  -->> SNAT with first_ip
2nd socket opened to b.b.b.b  -->> SNAT with first_ip
3rd socket opened to c.c.c.c  -->> SNAT with first_ip
4th socket opened to b.b.b.b  -->> SNAT with second_ip
5th socket opened to d.d.d.d  -->> SNAT with first_ip
6th socket opened to a.a.a.a  -->> SNAT with second_ip

I think it should work in this manner:

1st socket opened to a.a.a.a  -->> SNAT with first_ip
2nd socket opened to b.b.b.b  -->> SNAT with second_ip
3rd socket opened to c.c.c.c  -->> SNAT with first_ip
4th socket opened to b.b.b.b  -->> SNAT with second_ip
5th socket opened to d.d.d.d  -->> SNAT with first_ip
6th socket opened to a.a.a.a  -->> SNAT with second_ip

May anyone confirm this? Wrong or correct?

^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: snat to multiple source ip
@ 2005-09-20 19:00 Derick Anderson
  0 siblings, 0 replies; 17+ messages in thread
From: Derick Anderson @ 2005-09-20 19:00 UTC (permalink / raw)
  To: netfilter

 

> -----Original Message-----
> From: netfilter-bounces@lists.netfilter.org 
> [mailto:netfilter-bounces@lists.netfilter.org] On Behalf Of 
> Marco Berizzi
> Sent: Tuesday, September 20, 2005 11:17 AM
> To: netfilter@lists.netfilter.org
> Subject: Re: snat to multiple source ip
> 
> Derick Anderson wrote:
> 
> > Uneducated, lazy guess: the SNAT target supports only one 
> "--to [IP]"
> > and the command parser ignores the extraneous "--to [IP2]". You can
> test
> > this by switching the two IPs and see if you go out on a different 
> > address.
> 
> Nope!
> 
> >From "man iptables":
> 
> "...You  can  add  several --to-source options.  If you 
> specify more than one source address, either via an address 
> range or multiple --to-source options, a simple round-robin 
> (one after another in
> cycle) takes place between these adresses."

Well that's neat, I'll have to try that some time. Might work nicely as
a load balancer where I work.

Derick


^ permalink raw reply	[flat|nested] 17+ messages in thread
* RE: snat to multiple source ip
@ 2005-09-20 15:25 Harrison, Bruce (CXO)
  2005-09-20 15:53 ` Marco Berizzi
  0 siblings, 1 reply; 17+ messages in thread
From: Harrison, Bruce (CXO) @ 2005-09-20 15:25 UTC (permalink / raw)
  To: Marco Berizzi; +Cc: netfilter


Hello Marco,

    You're assuming that the man page accurately describes the behavior
of the code (which normally is the case).  But how about doing a quick
test as suggested by Derick just to be sure.  Could be a bug?

Have a Great Day!


Bruce...

-----Original Message-----
From: netfilter-bounces@lists.netfilter.org
[mailto:netfilter-bounces@lists.netfilter.org] On Behalf Of Marco
Berizzi
Sent: Tuesday, September 20, 2005 9:17 AM
To: netfilter@lists.netfilter.org
Subject: Re: snat to multiple source ip

Derick Anderson wrote:

> Uneducated, lazy guess: the SNAT target supports only one "--to [IP]"
> and the command parser ignores the extraneous "--to [IP2]". You can
test
> this by switching the two IPs and see if you go out on a different
> address.

Nope!

From "man iptables":

"...You  can  add  several --to-source options.  If you
specify more than one source address, either
via an address range or multiple --to-source options, a
simple round-robin (one after another in
cycle) takes place between these adresses."




^ permalink raw reply	[flat|nested] 17+ messages in thread
* snat to multiple source ip
@ 2005-09-20 12:39 Marco Berizzi
  2005-09-20 12:44 ` Edmundo Carmona
  2005-09-20 13:58 ` /dev/rob0
  0 siblings, 2 replies; 17+ messages in thread
From: Marco Berizzi @ 2005-09-20 12:39 UTC (permalink / raw)
  To: netfilter

Thanks for the reply Rob0.

On Thursday 2005-September-15 04:59, Marco Berizzi wrote:
>> My firewall script mark all the squid packet and I route them

>You did not post your rules.

This is not the real problem.
The problem is the SNAT rule. It is doesn't work as stated
by man. How does it work? Per socket? Or per socket per host?

iptables -t nat -I POSTROUTING -s HDSL_ip
--protocol tcp -m multiport --dports SQUIDports
-j SNAT --to first_adsl_ip --to second_adsl_ip

This rules snat all packets created by this (squid) host, but
everytime I connect to the internet *always* the first_adsl_ip
is chosen. My company lan has about 150 pc that connect to
the internet by this proxy, so I don't understand why *everytime*
I open my browser and I connect to www.dnsstuff.com always the
same ip is displayed. It isn't a cache problem because I reset them
(both on squid and browser side).

>> through the two adsl connections (I have patched the kernel
>> with the equalize patch).

> Which patch is this? I have used Julian Anastasov's patches

Here is http://www.ussg.iu.edu/hypermail/linux/kernel/0203.2/1314.html
However this is only for routing not for nat.




^ permalink raw reply	[flat|nested] 17+ messages in thread
* snat to multiple source ip
@ 2005-09-15  9:59 Marco Berizzi
  2005-09-15 12:21 ` /dev/rob0
  0 siblings, 1 reply; 17+ messages in thread
From: Marco Berizzi @ 2005-09-15  9:59 UTC (permalink / raw)
  To: netfilter

Hello everybody.

I have a system with Slackware linux 2.4.30 and squid 2.5s10.
Squid is running as an http proxy to control internet access.
This system is connected to the internet with 1 hdsl and
2 adsl connections.
My firewall script mark all the squid packet and I route them
through the two adsl connections (I have patched the kernel
with the equalize patch).
The problem is that Squid set the packet source ip with the
hdsl ip, so I need to snat them to the ADSLs ip:

iptables -t nat -I POSTROUTING -s HDSL_ip
--protocol tcp -m multiport --dports SQUIDports
-j SNAT --to first_adsl_ip --to second_adsl_ip

As stated by man:

"You can add several --to-source option. If you specify
more than one source address, either via an address range
or multiple --to-source options, a simple round-robin  (one
after another in cycle) takes place between these addresses."

Everytime I connect to the internet the ip address is *always*
the first_adsl_ip and after few refresh it change to second_adsl_ip
(I know there are chaching issue with proxy/browser).
Usually I connect to http://www.dnsstuff.com/ to control which is
my ip address. My company has about 150 pc that connect through this
proxy. Is this behaviour fine or am I missing anything?



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2005-09-26 17:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-20 15:07 snat to multiple source ip Derick Anderson
2005-09-20 15:16 ` Marco Berizzi
2005-09-20 15:24 ` Edmundo Carmona
  -- strict thread matches above, loose matches on Subject: below --
2005-09-26 15:38 Marco Berizzi
2005-09-26 16:10 ` Phil Oester
2005-09-26 16:39   ` Marco Berizzi
2005-09-26 17:47     ` Phil Oester
2005-09-20 19:00 Derick Anderson
2005-09-20 15:25 Harrison, Bruce (CXO)
2005-09-20 15:53 ` Marco Berizzi
2005-09-20 12:39 Marco Berizzi
2005-09-20 12:44 ` Edmundo Carmona
2005-09-20 13:37   ` Marco Berizzi
2005-09-20 13:58 ` /dev/rob0
2005-09-20 14:24   ` Marco Berizzi
2005-09-15  9:59 Marco Berizzi
2005-09-15 12:21 ` /dev/rob0

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.