iptables and nat

This is a discussion on iptables and nat within the Linux Networking forums, part of the Linux Forums category; Hello all, I have problem with iptable and nat. All I need to do is not nat packets where destination ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-05-2004
Marcin Giedz
 
Posts: n/a
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
Reply With Quote
  #2 (permalink)  
Old 07-05-2004
KR
 
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 (permalink)  
Old 07-05-2004
Marcin Giedz
 
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 (permalink)  
Old 07-05-2004
Kimmo Koivisto
 
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 (permalink)  
Old 07-06-2004
jack
 
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 (permalink)  
Old 07-06-2004
Marcin Giedz
 
Posts: n/a
Default Re: iptables and nat

THANK YOU ALL - marvellous :D

Marcin
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0