Skip to contentSkip to conversation

SNAT & default route

DISCUSSION Luca Raggi 2 participants 2 messages Jun 23, 2003 netfilter

lore
Share & tools
lore

Luca Raggi

author
#0 lore raw

Hi;

I'm trying to do source NAT and multiple-provider outbound load balancing at the same time, and while everything works with respect to incoming packets, I can't seem to get outbound packets out through the right device/gateway.

I tried the following approaches:

- Using MARK, CONNMARK, and fwmark to select an iproute2 table with the right default gateway. While the marks are set correctly (for both
packet
N=1 and packets N>=2), in the end the routing decision is apparently discarded, and the main default is used anyways (for all values of N.) This only happens for forwarded/SNAT'ed packets, however. Locally originating packets and non-SNAT'ed forwarded packets get routed correctly (via "ip rule from"'s that point to the same tables that the higher-priority "ip rule fwmark"'s point to.)

- Using SMASQ instead of SNAT. Here, again, the device indicated with --via-dev doesn't get used after all, and the main default is used instead. This is rather perplexing, since being able to choose the output device is SMASQ's raison d'etre.

- Using the ROUTE target in various places to try to force the correct behavior. Unfortunately, trying to ROUTE before SNAT'ing bypasses the SNAT'ing, and ROUTE'ing after the SNAT'ing is apparently impossible, since there's no chain after the nat/POSTROUTING chain in which to place the ROUTE rule.

Can anyone offer a hint as to what I may be running into here? Any pointers
as to where to look in the kernel source (2.4.21) would also be helpful.

Thanks!

Regards,
Luca Raggi

#1 lore raw

Hi Luca,

Quoted 9 lines

- Using MARK, CONNMARK, and fwmark to select an iproute2 table with the right default gateway. While the marks are set correctly (for both
packet
N=1 and packets N>=2), in the end the routing decision is apparently discarded, and the main default is used anyways (for all values of N.) This only happens for forwarded/SNAT'ed packets, however. Locally originating packets and non-SNAT'ed forwarded packets get routed correctly (via "ip rule from"'s that point to the same tables that the higher-priority "ip rule fwmark"'s point to.)

I haven't tried this with CONNMARK, but I know that iproute+MARK works because I've used it. Can you post examples of what rules you are using?

Quoted 5 lines

- Using the ROUTE target in various places to try to force the correct behavior. Unfortunately, trying to ROUTE before SNAT'ing bypasses the SNAT'ing, and ROUTE'ing after the SNAT'ing is apparently impossible, since there's no chain after the nat/POSTROUTING chain in which to place the ROUTE rule.

How about placing your ROUTE rule in mangle/FORWARD? There may be issues with the nat table only seeing the first packet of each connection.

If you put the ROUTE rule into mangle/POSTROUTING and the SNAT rule into nat/POSTROUTING, does it prevent the SNAT from being read?

Cheers, Chris.

Signature · 4 lines
   ___ __     _
 / __// / ,__(_)_  | Chris Wilson -- UNIX Firewall Lead Developer |
/ (_ / ,\/ _/ /_ \ | NetServers.co.uk http://www.netservers.co.uk |
\ _//_/_/_//_/___/ | 21 Signet Court, Cambridge, UK. 01223 576516 |