Skip to contentSkip to conversation

iptables target conflict? ROUTE and MASQUERADE

DISCUSSION Wu Nick 4 participants 4 messages Dec 16, 2003 netfilter

lore
Share & tools
lore

Wu Nick

author
#0 lore raw

Hey guys:

Have you ever encounter the problem when using iptables target ROUTE and MASQUERADE?

We all know that MASQUERADE is used in IP-sharing mechanism to change the source IP adderss. This is good when you have only one ppp connection. However, I've got several pppoe connections at the same time to connect the Internet. I dial up several pppoe connections at the same time, and I'm using ROUTE to redirect packets to different ppp interfaces. But this will defeat the design of MASQUERADE. That is, I'd like to send packets out from different ppp interfaces and their source IP addresses needed to be changed to the IP addess of the specific ppp interface. Do you have any idea about how to do?

Quoted 1 line

From the thread "[PATCH] update for ROUTE target in Netfilter-Extension

HOWTO", it mentioned that once the ROUTE target applies for a packet, the packet is

'stolen' and no further rues are consulted. But in this way I have no chance to change my source IP address of the packet (just like MASQUERADE did) with the ip address of actual outgoing ppp interface. I can't use MASQUERADE to change all packets' source IP a fixed ppp interface. How can I do? Any solution?

Nick

_________________________________________________________________
立即申請 MSN Mobile 服務:在您的手機上收發 MSN Hotmail http://msn.com.tw/msnmobile

#1 lore raw

Le mar 16/12/2003 a 09:55, Wu Nick a ecrit :

Quoted 6 lines
Quoted 1 line

From the thread "[PATCH] update for ROUTE target in Netfilter-Extension

HOWTO",
it mentioned that once the ROUTE target applies for a packet, the packet is 'stolen' and no further rues are consulted. But in this way I have no chance to change my source IP address of the packet (just like MASQUERADE did) with the ip address of actual outgoing ppp interface.

There is a new option (--continue) for the ROUTE target that prevents the target from stealing the packet. Maybe this could help.

Cedric

#2 lore raw
In reply to Wu Nick
Quoted 3 lines · Wu Nick

That is, I'd like to send packets out from different ppp interfaces and their source IP addresses needed to be changed to the IP addess of the specific ppp interface. Do you have any idea about how to do?

I have been doing this kind of thing for 2 pppoe connections with the following setup:

In PREROUTING, table mangle, I mark the packets for each ppp:
iptables -A PREROUTING -t mangle -j MARK --set-mark 0x1 -p tcp --dport 80-82 iptables -A PREROUTING -t mangle -j MARK --set-mark 0x2 -p tcp --dport 25

I create routing rules (not routing entries) that will effectivelly separate the packets for each pppoe connection:
ip rule add fwmark 1 pref 110 table adsl1
ip rule add fwmark 2 pref 120 table adsl2

Finally, in the POSTROUTING, table nat, I SNAT the packets for each ppppoe connection:
iptables -A POSTROUTING -t nat -o ppp0 -j SNAT --to-source <ppp0_valid_address>
iptables -A POSTROUTING -t nat -o ppp1 -j SNAT --to-source <ppp1_valid_address>

A few comments:

I created this setup more than 2 years ago, before the CONFIG_IP_NF_TARGET_ROUTE and the CONFIG_IP_NF_NAT_LOCAL existed. I'm not sure that nowadays this is the best approach. It surelly was the only one that worked for me in 2000.

Using SNAT instead of MASQUERADE means that I have to recreate the nat rules each time a pppoe connection goes up. I had to do this because MASQUERADE wouldn't work on locally generated connections, only SNAT.

I hope all this is of any help,

Rodrigo Severo

Signature · 9 lines
----------------------------------------------------
Rodrigo Severo
Fa'brica de Ide'ias
Fone: +55(61)321 1357
Fax: +55(61)223 1712
SBS - Quadra 2 - Ed. Empire Center - Sala 1301
Brasi'lia/DF - Brasil
CEP: 70.070-904
----------------------------------------------------
#3 lore raw

Re: iptables target conflict? ROUTE and MASQUERADE [off-topic]

In reply to Wu Nick
Quoted 11 lines · Wu Nick

However,
I've
got several pppoe connections at the same time to connect the Internet. I dial
up several pppoe connections at the same time, and I'm using ROUTE to redirect
packets to different ppp interfaces. But this will defeat the design of MASQUERADE. That is, I'd like to send packets out from different ppp interfaces
and their source IP addresses needed to be changed to the IP addess of the specific ppp interface. Do you have any idea about how to do?

Don't know what you are up to but it sounds like "load balancing" to me. I have three pppoe connections "balancing" traffic from intranet to internet.

I have to use two computers to do the trick:
intranet --> computer 1 --> computer 2 --> internet

I have several computers in my intranet (x.x.0.0). Computer 1 does

   -t nat -A POSTROUTING -o ethx  -s x.x.0.0 \
     -j SNAT --to-source  x.x.1.20-x.x.1.22
That is, gives random ip for outgoing connection (this is the
"balancing"). Computer 2 does
   -t nat -A POSTROUTING -o ppp0 -s x.x.1.20 -j  MASQUERADE
   -t nat -A POSTROUTING -o ppp1 -s x.x.1.21 -j  MASQUERADE
   -t nat -A POSTROUTING -o ppp2 -s x.x.1.22 -j  MASQUERADE

and
ip rule add from x.x.1.20 table pppoe0
ip rule add from x.x.1.21 table pppoe1
ip rule add from x.x.1.22 table pppoe2

Problems with the solution: 1/3 rd of the passive ftp connection attempts fail. Masquerade will broke if ip changes for any ppp (this might be distribution specific problem).

There are probably far more elegant solutions. Using singe computer to do the job wasn't possible at the time I build it. Nowadays, dunno.

Regards,
Juha Heljoranta
juha.heljoranta-AT-evitech.fi