Linux Netfilter discussions
 help / color / mirror / Atom feed
* SNAT range does not use unique IP
@ 2013-12-12 21:55 Igor S
  2013-12-12 22:34 ` Phil Oester
  0 siblings, 1 reply; 8+ messages in thread
From: Igor S @ 2013-12-12 21:55 UTC (permalink / raw)
  To: netfilter

Dear netfilter guru's

I am trying to build a kind of a dynamic 1:1 SNAT gateway that is 
supposed to build every incoming IP to a unique internal IP in the 
internal network without any port mangling.

I did setup an SNAT range big enough to uniquely translate more than 8K 
addresses:
iptables -t nat -A POSTROUTING -s 100.0.0.0/8 -j SNAT -o eth2 --to  
12.0.1.1-12.0.33.254 --persistent

However before the range was exhausted conntrack started to report 
multiple source IP addresses translated to the same SNAT IP:
e.g. both 100.0.58.1:7 and 100.0.29.1:7 connections were translated to 
the same 12.0.8.241:7

cat /proc/net/nf_conntrack |grep 12.0.8.241
ipv4     2 udp      17 3 src=100.0.58.1 dst=12.2.58.1 sport=7 dport=7 
[UNREPLIED] src=12.2.58.1 dst=12.0.8.241 sport=7 dport=7 mark=0 zone=0 
use=2
ipv4     2 udp      17 3 src=100.0.29.1 dst=12.2.29.1 sport=7 dport=7 
[UNREPLIED] src=12.2.29.1 dst=12.0.8.241 sport=7 dport=7 mark=0 zone=0 
use=2

Isn't the nat module supposed to select a unique NAT IP in this case?

What would be a more appropriate way to make a unique 1:1 translation 
without knowing the exact source IP in advance?
Thanks,
Igor



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

* Re: SNAT range does not use unique IP
  2013-12-12 21:55 SNAT range does not use unique IP Igor S
@ 2013-12-12 22:34 ` Phil Oester
  2013-12-13 14:34   ` Igor S
  0 siblings, 1 reply; 8+ messages in thread
From: Phil Oester @ 2013-12-12 22:34 UTC (permalink / raw)
  To: Igor S; +Cc: netfilter

On Thu, Dec 12, 2013 at 10:55:53PM +0100, Igor S wrote:
> Dear netfilter guru's
> 
> I am trying to build a kind of a dynamic 1:1 SNAT gateway that is
> supposed to build every incoming IP to a unique internal IP in the
> internal network without any port mangling.

Then you should be using the NETMAP target.

   NETMAP (IPv4-specific)
       This target allows you to statically map a whole network of addresses onto another network of addresses.   It  can
       only be used from rules in the nat table.

       --to address[/mask]
              Network  address to map to.  The resulting address will be constructed in the following way: All 'one' bits
              in the mask are filled in from the new `address'.  All bits that are zero in the mask are  filled  in  from
              the original address.


Phil

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

* Re: SNAT range does not use unique IP
  2013-12-12 22:34 ` Phil Oester
@ 2013-12-13 14:34   ` Igor S
  2013-12-13 17:21     ` Phil Oester
  0 siblings, 1 reply; 8+ messages in thread
From: Igor S @ 2013-12-13 14:34 UTC (permalink / raw)
  To: Phil Oester; +Cc: netfilter

On Thu, 12 Dec 2013 14:34:44 -0800, Phil Oester wrote:
> On Thu, Dec 12, 2013 at 10:55:53PM +0100, Igor S wrote:
>> Dear netfilter guru's
>>
>> I am trying to build a kind of a dynamic 1:1 SNAT gateway that is
>> supposed to build every incoming IP to a unique internal IP in the
>> internal network without any port mangling.
>
> Then you should be using the NETMAP target.
>
>    NETMAP (IPv4-specific)
>        This target allows you to statically map a whole network of
> addresses onto another network of addresses.   It  can
>        only be used from rules in the nat table.
>
>        --to address[/mask]
>               Network  address to map to.  The resulting address will
> be constructed in the following way: All 'one' bits
>               in the mask are filled in from the new `address'.  All
> bits that are zero in the mask are  filled  in  from
>               the original address.
>
>
> Phil

Hi Phil,
Thanks for the quick reply
NETMAP would not be good for my case as the server is not supposed to 
handle the entire 100.0.0.0/8 network. It only has to map the number of 
addresses specified in the range. And i need to know in advance what 
addresses can be used on a particular NAT server.
The idea of using SNAT is to "compress" the source network and 
translate only the active clients.

Thanks,
Igor



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

* Re: SNAT range does not use unique IP
  2013-12-13 14:34   ` Igor S
@ 2013-12-13 17:21     ` Phil Oester
  2013-12-16  8:17       ` Igor S
  0 siblings, 1 reply; 8+ messages in thread
From: Phil Oester @ 2013-12-13 17:21 UTC (permalink / raw)
  To: Igor S; +Cc: netfilter

On Fri, Dec 13, 2013 at 03:34:33PM +0100, Igor S wrote:
> On Thu, 12 Dec 2013 14:34:44 -0800, Phil Oester wrote:
> >On Thu, Dec 12, 2013 at 10:55:53PM +0100, Igor S wrote:
> >>I am trying to build a kind of a dynamic 1:1 SNAT gateway that is
> >>supposed to build every incoming IP to a unique internal IP in the
> >>internal network without any port mangling.
> >
> >Then you should be using the NETMAP target.

> Hi Phil,
> Thanks for the quick reply
> NETMAP would not be good for my case as the server is not supposed
> to handle the entire 100.0.0.0/8 network. It only has to map the
> number of addresses specified in the range. And i need to know in
> advance what addresses can be used on a particular NAT server.
> The idea of using SNAT is to "compress" the source network and
> translate only the active clients.

Unfortunately, SNAT and NETMAP are the only two options available.

Phil

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

* Re: SNAT range does not use unique IP
  2013-12-13 17:21     ` Phil Oester
@ 2013-12-16  8:17       ` Igor S
  2013-12-16  9:23         ` Pascal Hambourg
  0 siblings, 1 reply; 8+ messages in thread
From: Igor S @ 2013-12-16  8:17 UTC (permalink / raw)
  To: Phil Oester; +Cc: netfilter

On Fri, 13 Dec 2013 09:21:16 -0800, Phil Oester wrote:
> On Fri, Dec 13, 2013 at 03:34:33PM +0100, Igor S wrote:
>> On Thu, 12 Dec 2013 14:34:44 -0800, Phil Oester wrote:
>> >On Thu, Dec 12, 2013 at 10:55:53PM +0100, Igor S wrote:
>> >>I am trying to build a kind of a dynamic 1:1 SNAT gateway that is
>> >>supposed to build every incoming IP to a unique internal IP in the
>> >>internal network without any port mangling.
>> >
>> >Then you should be using the NETMAP target.
>
>> Hi Phil,
>> Thanks for the quick reply
>> NETMAP would not be good for my case as the server is not supposed
>> to handle the entire 100.0.0.0/8 network. It only has to map the
>> number of addresses specified in the range. And i need to know in
>> advance what addresses can be used on a particular NAT server.
>> The idea of using SNAT is to "compress" the source network and
>> translate only the active clients.
>
> Unfortunately, SNAT and NETMAP are the only two options available.
>
> Phil

Understood. But is it normal that NAT uses absolutely the same IP/port 
combination for different source IP's?
Igor

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

* Re: SNAT range does not use unique IP
  2013-12-16  8:17       ` Igor S
@ 2013-12-16  9:23         ` Pascal Hambourg
  2013-12-17 11:05           ` Igor S
  2013-12-17 11:07           ` Igor S
  0 siblings, 2 replies; 8+ messages in thread
From: Pascal Hambourg @ 2013-12-16  9:23 UTC (permalink / raw)
  To: Igor S; +Cc: netfilter

Igor S a écrit :
> 
> Understood. But is it normal that NAT uses absolutely the same IP/port 
> combination for different source IP's?

Yes, as long as the destination address/port are different.

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

* Re: SNAT range does not use unique IP
  2013-12-16  9:23         ` Pascal Hambourg
@ 2013-12-17 11:05           ` Igor S
  2013-12-17 11:07           ` Igor S
  1 sibling, 0 replies; 8+ messages in thread
From: Igor S @ 2013-12-17 11:05 UTC (permalink / raw)
  To: Pascal Hambourg; +Cc: netfilter

On Mon, 16 Dec 2013 10:23:01 +0100, Pascal Hambourg wrote:
> Igor S a écrit :
>>
>> Understood. But is it normal that NAT uses absolutely the same 
>> IP/port
>> combination for different source IP's?
>
> Yes, as long as the destination address/port are different.

OK. that does not allow to maintain the required consistency in the 
target network. Different clients may use the same SRC IP; the same 
client may appear to use different SRC IP addresses when talking to 
different servers in the same destination network.

Any suggestions how I could change the NAT code to prevent it from 
using the same SNAT IP address for different clients?

Thanks,
Igor


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

* Re: SNAT range does not use unique IP
  2013-12-16  9:23         ` Pascal Hambourg
  2013-12-17 11:05           ` Igor S
@ 2013-12-17 11:07           ` Igor S
  1 sibling, 0 replies; 8+ messages in thread
From: Igor S @ 2013-12-17 11:07 UTC (permalink / raw)
  To: Pascal Hambourg; +Cc: netfilter

On Mon, 16 Dec 2013 10:23:01 +0100, Pascal Hambourg wrote:
> Igor S a écrit :
>>
>> Understood. But is it normal that NAT uses absolutely the same 
>> IP/port
>> combination for different source IP's?
>
> Yes, as long as the destination address/port are different.

OK. that does not allow to maintain the required consistency in the 
target network. Different clients may use the same SRC IP; the same 
client may appear to use different SRC IP addresses when talking to 
different servers in the same destination network.

Any suggestions how I could change the NAT code to prevent it from 
using the same SNAT IP address for different clients?

Thanks,
Igor


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

end of thread, other threads:[~2013-12-17 11:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-12 21:55 SNAT range does not use unique IP Igor S
2013-12-12 22:34 ` Phil Oester
2013-12-13 14:34   ` Igor S
2013-12-13 17:21     ` Phil Oester
2013-12-16  8:17       ` Igor S
2013-12-16  9:23         ` Pascal Hambourg
2013-12-17 11:05           ` Igor S
2013-12-17 11:07           ` Igor S

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox