List Info

Thread: RE: howto make SNAT preserve translation ip for all connections fromthe same internal ip




RE: howto make SNAT preserve translation ip for all connections fromthe same internal ip
country flaguser name
United States
2007-06-30 09:21:27
Well, is not enough add

-s 192.168.0.0/24

to the rule?

Jorge Dávila.

>    Hi, all.
>Say, I use iptables -t nat -A POSTROUTING -p tcp -o eth0
-j SNAT --to-source 
>194.236.50.1-194.236.50.7 for NAT. Accordingly to man:
>The source IP for each stream that we open would then be
allocated randomly 
>from these (194.236.50.1-194.236.50.7), and a single
stream would always use 
>the same IP address for all packets within that stream.
>
>What if I want that internal ip from block
192.168.0.0/24 is always translated 
>into the same external ip?
>PF from OpenBSD does it:
>
>     For nat and rdr rules, (as well as for the
route-to, reply-to and dup-to
>     rule options) for which there is a single
redirection address which has 
>a
>     subnet mask smaller than 32 for IPv4 or 128 for
IPv6 (more than one IP
>     address), a variety of different methods for
assigning this address can
>     be used:
>
>     bitmask
>           The bitmask option applies the network
portion of the redirection
>           address to the address to be modified (source
with nat, 
>destination
>           with rdr).
>
>     random
>           The random option selects an address at
random within the defined
>           block of addresses.
>
>     source-hash
>           The source-hash option uses a hash of the
source address to deter-
>           mine the redirection address, ensuring that
the redirection 
>address
>           is always the same for a given source.  An
optional key can be
>           specified after this keyword either in hex or
as a string; by de-
>           fault pfctl(8) randomly generates a key for
source-hash every time
>           the ruleset is reloaded.
>
>     round-robin
>           The round-robin option loops through the
redirection address(es).
>
>           When more than one redirection address is
specified, round-robin 
>is
>           the only permitted pool type.
>
>     static-port
>           With nat rules, the static-port option
prevents pf(4) from modify-
>           ing the source port on TCP and UDP packets.
>
>     Additionally, the sticky-address option can be
specified to help ensure
>     that multiple connections from the same source are
mapped to the same
>     redirection address.  This option can be used with
the random and round-
>     robin pool options.  Note that by default these
associations are de-
>     stroyed as soon as there are no longer states which
refer to them; in 
>or-
>     der to make the mappings last beyond the lifetime
of the states, 
>increase
>     the global options with set timeout src.track.  See
STATEFUL TRACKING
>     OPTIONS for more ways to control the source
tracking. 
>   
>



-- 
Jorge Isaac Davila Lopez
Nicaragua Open Source
+505 430 5462
davilanicaraguaopensource.com


Re: howto make SNAT preserve translation ip for all connectionsfromthe same internal ip
user name
2007-06-30 14:38:07
Hello, Jorge Davila 
óÂ, 30.06.2007 16:21:27 you wrote:

JD> Well, is not enough add
JD> -s 192.168.0.0/24
JD> to the rule?
JD> Jorge Dç¡vila.

No, I want that any connection (different streams) from
particular ip of internal network always nated to the same
external ip.
Is it by default? 

JD> >    Hi, all.
JD> >Say, I use iptables -t nat -A POSTROUTING -p tcp
-o eth0 -j SNAT --to-source 
JD> >194.236.50.1-194.236.50.7 for NAT. Accordingly to
man:
JD> >The source IP for each stream that we open would
then be allocated randomly 
JD> >from these (194.236.50.1-194.236.50.7), and a
single stream would always use 
JD> >the same IP address for all packets within that
stream.
JD> >
JD> >What if I want that internal ip from block
192.168.0.0/24 is always translated 
JD> >into the same external ip?
JD> >PF from OpenBSD does it:
JD> >
JD> >     For nat and rdr rules, (as well as for the
route-to, reply-to and dup-to
JD> >     rule options) for which there is a single
redirection address which has 
JD> >a
JD> >     subnet mask smaller than 32 for IPv4 or 128
for IPv6 (more than one IP
JD> >     address), a variety of different methods for
assigning this address can
JD> >     be used:
JD> >
JD> >     bitmask
JD> >           The bitmask option applies the network
portion of the redirection
JD> >           address to the address to be modified
(source with nat, 
JD> >destination
JD> >           with rdr).
JD> >
JD> >     random
JD> >           The random option selects an address
at random within the defined
JD> >           block of addresses.
JD> >
JD> >     source-hash
JD> >           The source-hash option uses a hash of
the source address to deter-
JD> >           mine the redirection address, ensuring
that the redirection 
JD> >address
JD> >           is always the same for a given source.
 An optional key can be
JD> >           specified after this keyword either in
hex or as a string; by de-
JD> >           fault pfctl(8) randomly generates a
key for source-hash every time
JD> >           the ruleset is reloaded.
JD> >
JD> >     round-robin
JD> >           The round-robin option loops through
the redirection address(es).
JD> >
JD> >           When more than one redirection address
is specified, round-robin 
JD> >is
JD> >           the only permitted pool type.
JD> >
JD> >     static-port
JD> >           With nat rules, the static-port option
prevents pf(4) from modify-
JD> >           ing the source port on TCP and UDP
packets.
JD> >
JD> >     Additionally, the sticky-address option can
be specified to help ensure
JD> >     that multiple connections from the same
source are mapped to the same
JD> >     redirection address.  This option can be
used with the random and round-
JD> >     robin pool options.  Note that by default
these associations are de-
JD> >     stroyed as soon as there are no longer
states which refer to them; in 
JD> >or-
JD> >     der to make the mappings last beyond the
lifetime of the states, 
JD> >increase
JD> >     the global options with set timeout
src.track.  See STATEFUL TRACKING
JD> >     OPTIONS for more ways to control the source
tracking. 
JD> >   
JD> >
JD> -- 
JD> Jorge Isaac Davila Lopez
JD> Nicaragua Open Source
JD> +505 430 5462
JD> davilanicaraguaopensource.com


Igor Popov <igorpopovnewmail.ru>
icq 241601876
jid ipopovigmail.com

__________
www.newmail.ru -- ×ÓÅÇÄÁ ÞÔÏ-ÔÏ ÎÏ×ÏÅ.


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )