Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
IPTables NAT
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
ceicke
n00b
n00b


Joined: 20 Jul 2006
Posts: 23
Location: DE, Hamburg

PostPosted: Wed Apr 29, 2009 12:44 pm    Post subject: IPTables NAT Reply with quote

Hi,

I have the following problem that I can't seem to fix.

I have two networks at hand: 192.168.2.0/24 and 192.168.4.0/24. Between the two networks I would like to do some sort of NATing, so that in network 192.168.2.0/24, host 192.168.4.X appears as 192.168.2.X and vice verca.

Unfortunately, SNAT doesn't allow the following thing:

Code:
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.2.0/24 -j SNAT --to 192.168.4.0/24


Am I missing something? Is there a completely obvious way to do this?

Thanks,
Christoph
Back to top
View user's profile Send private message
xtz
Apprentice
Apprentice


Joined: 29 Oct 2007
Posts: 181
Location: Singapore

PostPosted: Wed Apr 29, 2009 1:09 pm    Post subject: Reply with quote

If you just want the two networks to be able to access each other, enable the IP forwarding in /etc/sysctl.conf
Back to top
View user's profile Send private message
ceicke
n00b
n00b


Joined: 20 Jul 2006
Posts: 23
Location: DE, Hamburg

PostPosted: Wed Apr 29, 2009 1:28 pm    Post subject: Reply with quote

Well, of course that's what I want and that's happening already. At this point I'm doing masquerading, but let me stress this point again: I specifically want this IP mapping and not in the way that everything appears to come from one IP (which is happening in the case of doing masquerading).
Back to top
View user's profile Send private message
szmytson
n00b
n00b


Joined: 29 Apr 2009
Posts: 20
Location: UK

PostPosted: Wed Apr 29, 2009 1:37 pm    Post subject: Re: IPTables NAT Reply with quote

Hi,

I guess there is no smart way to achieve this...

The manual way would be something like this:
Code:
perl -e 'foreach $i (1..254) {print "iptables -t nat -A POSTROUTING -o eth0 -s 192.168.2.$i -j SNAT --to 192.168.4.$i" . "\n";}'
Back to top
View user's profile Send private message
xtz
Apprentice
Apprentice


Joined: 29 Oct 2007
Posts: 181
Location: Singapore

PostPosted: Wed Apr 29, 2009 2:05 pm    Post subject: Reply with quote

AFAIK, u cannot SNAT a whole network just like this. I think a single rule is needed to SNAT from each separate address to anothe separate one.
Back to top
View user's profile Send private message
Mad Merlin
Veteran
Veteran


Joined: 09 May 2005
Posts: 1155

PostPosted: Thu Apr 30, 2009 1:24 am    Post subject: Reply with quote

Is there a reason you're not just using a 192.168.0.0/16 network? Then all machines could talk directly to eachother.

Anyways, with the NETMAP target I think you can do what you're hoping for:

Code:

   NETMAP
       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 con-
              structed 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.

_________________
Game! - Where the stick is mightier than the sword!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum