Networking Forums  

Go Back   Networking Forums > Networking Newsgroups > Linux Networking

iptables and nat

Reply
 
Thread Tools Display Modes
  #1  
Old 07-05-2004, 05:53 PM
Default iptables and nat



Hello all,

I have problem with iptable and nat. All I need to do is not nat packets
where destination address is 192.168.2.0/25 and 192.168.59.0/24 and
192.168.3.0./24

This is a fragment of my iptables script
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.10.10.2
iptables -t nat -A POSTROUTING -d ! 192.168.2.0/24 -o eth0 -j SNAT --to
10.10.10.2
iptables -t nat -A POSTROUTING -d ! 192.168.59.0/24 -o eth0 -j SNAT --to
10.10.10.2
iptables -t nat -A POSTROUTING -d ! 192.168.3.0/24 -o eth0 -j SNAT --to
10.10.10.2

In my opinion every packets sent to 192.168.2.x or 192.168.3.x or
192.168.59.x shouldn't be nat.

What is wrong with this?

Thx,
Marcin Giedz


Marcin Giedz
Reply With Quote
  #2  
Old 07-05-2004, 05:59 PM
KR
Guest
 
Posts: n/a
Default Re: iptables and nat

Marcin Giedz wrote:
>
> I have problem with iptable and nat. All I need to do is not nat packets
> where destination address is 192.168.2.0/25 and 192.168.59.0/24 and
> 192.168.3.0./24
>
> This is a fragment of my iptables script
> iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.10.10.2
> iptables -t nat -A POSTROUTING -d ! 192.168.2.0/24 -o eth0 -j SNAT --to
> 10.10.10.2
> iptables -t nat -A POSTROUTING -d ! 192.168.59.0/24 -o eth0 -j SNAT --to
> 10.10.10.2
> iptables -t nat -A POSTROUTING -d ! 192.168.3.0/24 -o eth0 -j SNAT --to
> 10.10.10.2


First, you're NATing all traffic where the destination is not
192.168.2.0/24. Then you're doing the same for 192.168.59.0/24 and
192.168.3.0/24. In other words, no matter what the destination IP is, a
packet is bound to match at least two of those rules.

Reply With Quote
  #3  
Old 07-05-2004, 06:04 PM
Marcin Giedz
Guest
 
Posts: n/a
Default Re: iptables and nat

KR wrote:

> Marcin Giedz wrote:
>>
>> I have problem with iptable and nat. All I need to do is not nat packets
>> where destination address is 192.168.2.0/25 and 192.168.59.0/24 and
>> 192.168.3.0./24
>>
>> This is a fragment of my iptables script
>> iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.10.10.2
>> iptables -t nat -A POSTROUTING -d ! 192.168.2.0/24 -o eth0 -j SNAT --to
>> 10.10.10.2
>> iptables -t nat -A POSTROUTING -d ! 192.168.59.0/24 -o eth0 -j SNAT --to
>> 10.10.10.2
>> iptables -t nat -A POSTROUTING -d ! 192.168.3.0/24 -o eth0 -j SNAT --to
>> 10.10.10.2

>
> First, you're NATing all traffic where the destination is not
> 192.168.2.0/24. Then you're doing the same for 192.168.59.0/24 and
> 192.168.3.0/24. In other words, no matter what the destination IP is, a
> packet is bound to match at least two of those rules.


So how to write rules to not NATing these subnets?

Marcin

Reply With Quote
  #4  
Old 07-05-2004, 06:26 PM
Kimmo Koivisto
Guest
 
Posts: n/a
Default Re: iptables and nat

Marcin Giedz wrote:

> KR wrote:
>
>> Marcin Giedz wrote:
>>>
>>> I have problem with iptable and nat. All I need to do is not nat packets
>>> where destination address is 192.168.2.0/25 and 192.168.59.0/24 and
>>> 192.168.3.0./24
>>>
>>> This is a fragment of my iptables script
>>> iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.10.10.2
>>> iptables -t nat -A POSTROUTING -d ! 192.168.2.0/24 -o eth0 -j SNAT --to
>>> 10.10.10.2
>>> iptables -t nat -A POSTROUTING -d ! 192.168.59.0/24 -o eth0 -j SNAT --to
>>> 10.10.10.2
>>> iptables -t nat -A POSTROUTING -d ! 192.168.3.0/24 -o eth0 -j SNAT --to
>>> 10.10.10.2

>>
>> First, you're NATing all traffic where the destination is not
>> 192.168.2.0/24. Then you're doing the same for 192.168.59.0/24 and
>> 192.168.3.0/24. In other words, no matter what the destination IP is, a
>> packet is bound to match at least two of those rules.

>
> So how to write rules to not NATing these subnets?
>
> Marcin


Try this:

iptables -t nat -A POSTROUTING -d 192.168.2.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -d 192.168.59.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -d 192.168.3.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.10.10.2


Kimmo
Reply With Quote
  #5  
Old 07-06-2004, 12:38 AM
jack
Guest
 
Posts: n/a
Default Re: iptables and nat

Marcin Giedz wrote:
> Hello all,
>
> I have problem with iptable and nat. All I need to do is not nat packets
> where destination address is 192.168.2.0/25 and 192.168.59.0/24 and
> 192.168.3.0./24
>
> This is a fragment of my iptables script
> iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.10.10.2
> iptables -t nat -A POSTROUTING -d ! 192.168.2.0/24 -o eth0 -j SNAT --to
> 10.10.10.2
> iptables -t nat -A POSTROUTING -d ! 192.168.59.0/24 -o eth0 -j SNAT --to
> 10.10.10.2
> iptables -t nat -A POSTROUTING -d ! 192.168.3.0/24 -o eth0 -j SNAT --to
> 10.10.10.2
>
> In my opinion every packets sent to 192.168.2.x or 192.168.3.x or
> 192.168.59.x shouldn't be nat.
>
> What is wrong with this?


This is a conceptional error.

I'm not going to go in-depth, which obviously I should do here, but I'll
have to add that later.

Firstly, please note that the order of the rules is significant. So if
You decide on the outgoing interface eth0, Your first rule here will
catch off all packets from the other rules. They will never be seen by
the packets in question.

Then, You're addressing the problem from the wrong direction:

Firstly, filter out the packets that You want to leave untouched, like
so:
iptables -t nat -A POSTROUTING -d 192.168.2.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -d 192.168.3.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -d 192.168.59.0/24 -o eth0 -j ACCEPT

, and then, insert Your "catch-all" rule:
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 10.10.10.2

You're not tellng us anything about the environment these rules live
in, but perhaps You might want to MASQUERADE instead of SNAT.


Cheers, Jack.

--
----------------------------------------------------------------------
My personal reading of the string "MicroSoft" expands to "NanoWeak"...
Reply With Quote
  #6  
Old 07-06-2004, 08:05 AM
Marcin Giedz
Guest
 
Posts: n/a
Default Re: iptables and nat

THANK YOU ALL - marvellous

Marcin
Reply With Quote
Reply

Tags
iptables, nat

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 03:46 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.