Skip to contentSkip to conversation

NATed packets only enter the default routing table

DISCUSSION richard lucassen 3 participants 4 messages Apr 8, 2006 – Apr 9, 2006

lore
Share & tools
lore
#0 lore raw

(copy from lartc mailinglist)

I set up this config:

+------+
-+ ISP1 +--+

 +------+  |  +-------+
           +--+ linux |
 +------+  |  +-------+

-+ ISP2 +--+
+------+

No problem. Standard setup with two ISP's. Both routed subnets. Default gateway is ISP1. No magic here.

Now I put a server behind the Linux box. I want the server to be reachable on an /extra/ IP in the routed subnet of ISP2.

+------+
-+ ISP1 +--+

 +------+  |  +-------+  +-----------------+
           +--+ linux +--+ server 10.0.0.2 |
 +------+  |  +-------+  +-----------------+

-+ ISP2 +--+
+------+

router ISP2: 1.2.3.1/24
dev ISP2: eth1
Linux box eth1: 1.2.3.2/24
external ip ISP2 for server 10.0.0.2: 1.2.3.3

arp -s 1.2.3.3 aa:bb:cc:dd:ee:ff pub
ip route add 1.2.3.3 via 10.0.0.2
iptables -t nat -A PREROUTING -i eth1 -d 1.2.3.3 -j DNAT --to 10.0.0.2

When pinging 1.2.3.3, the packets get in through eth1 (ok), but the replies are following the default routing table through eth0 (wrong)

Even a

ip rule add from 1.2.3.3 lookup table_eth1

doesn't change this behaviour. It is working ok when I add the address 1.2.3.3 directly to eth1 (without NAT):

ip a a 1.2.3.3 dev eth1

Why is this?

R.

Signature · 9 lines
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
| Public key and email address:                                    |
| http://www.lucassen.org/mail-pubkey.html                         |
+------------------------------------------------------------------+
#1 lore raw

Hi,
i had a similar problem with our setup. The problem is i think that the routing decision on the linux box is made before the address in the packet is changed back to 1.2.3.3. So it doesn't use the source policy routing entry. I solved this by using the connmark module from iptables and then do routing based on the mark. The following should work in your setup:

iptables -t mangle -I PREROUTING -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
iptables -t mangle -I PREROUTING -i eth1 -m conntrack --ctstate NEW -j CONNMARK --set-mark 1

ip rule add fwmark 1 lookup eth1_up

This will route everything that entered via eth1 back via eth1.

Greetings,
jeroen

#2 lore raw
Quoted 7 lines · On Sun, 9 Apr 2006 15:56:02 +0200 Jeroen Elebaut <[email protected]> wrote:

i had a similar problem with our setup. The problem is i think that the routing decision on the linux box is made before the address in the packet is changed back to 1.2.3.3. So it doesn't use the source policy routing entry. I solved this by using the connmark module from iptables and then do routing based on the mark. The following should work in your setup:

Quoted 6 lines

iptables -t mangle -I PREROUTING -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
iptables -t mangle -I PREROUTING -i eth1 -m conntrack --ctstate NEW -j CONNMARK --set-mark 1

ip rule add fwmark 1 lookup eth1_up

I already found out this:

iptables -t mangle -A PREROUTING -i eth1 -d 192.168.201.3 \
-j CONNMARK --set-mark 1

iptables -t mangle -A PREROUTING -i eth2 -s 10.0.2.1 \
-j CONNMARK --restore-mark

Quoted 1 line

This will route everything that entered via eth1 back via eth1.

And indeed that was the solution. Thnx!

R.

Signature · 9 lines
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
| Public key and email address:                                    |
| http://www.lucassen.org/mail-pubkey.html                         |
+------------------------------------------------------------------+
#3 lore raw
Quoted 22 lines · richard lucassen
Quoted 7 lines · On Sun, 9 Apr 2006 15:56:02 +0200 Jeroen Elebaut <[email protected]> wrote:

i had a similar problem with our setup. The problem is i think that the routing decision on the linux box is made before the address in the packet is changed back to 1.2.3.3. So it doesn't use the source policy routing entry. I solved this by using the connmark module from iptables and then do routing based on the mark. The following should work in your setup:

Quoted 6 lines

iptables -t mangle -I PREROUTING -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
iptables -t mangle -I PREROUTING -i eth1 -m conntrack --ctstate NEW -j CONNMARK --set-mark 1

ip rule add fwmark 1 lookup eth1_up

I already found out this:

iptables -t mangle -A PREROUTING -i eth1 -d 192.168.201.3 \
-j CONNMARK --set-mark 1

Quoted 8 lines

iptables -t mangle -A PREROUTING -i eth2 -s 10.0.2.1 \
-j CONNMARK --restore-mark

Quoted 1 line

This will route everything that entered via eth1 back via eth1.

And indeed that was the solution. Thnx!

R.

Are the kernel patches from here http://www.ssi.bg/~ja/ the ones that fix this problem as well.

Quoted 13 lines
Signature · 10 lines
-- 
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
| Public key and email address:                                    |
| http://www.lucassen.org/mail-pubkey.html                         |
+------------------------------------------------------------------+