Skip to contentSkip to conversation

Routing traffic over two gateways by fwmark

DISCUSSION Matt Killock 2 participants 3 messages Mar 31, 2015 – Apr 2, 2015

lore
Share & tools
lore
#0 lore raw

Hello,

I am having trouble re-using scripts that worked in kernel 2.6.24 with a more recent 3.16.0 series kernel. The essence of what I am trying to do is this:

iptables mark all packets arriving from anywhere on interface 1 with '10' iptables mark all packets arriving from anywhere on interface 2 with '20'

iptables DNAT incoming traffic on interface 1 on port 1111 to internal server via interface 3 iptables DNAT incoming traffic on interface 2 on port 1111 to internal server via interface 3

ip rule from all fwmark 10 table T1
ip rule from all fwmark 20 table T2

default gateway in table T1 is through interface 1 default gateway in table T2 is through interface 2

With the view to make everything that arrives on a particular interface leave via that interface. The above approach worked fine in kernel 2.6 but does not seem to work any more. With no default gateway in the main routing table, the packets arrive on the external interfaces but do not appear on the LAN interface, almost as if DNAT is having no effect at all. One of the two DNAT rules works if I add a default gateway to the main routing table, but then it appears that the policy routing tables or firewall marks are ignored.

Should the above approach be possible still? If not, then could someone advise what approach I should use nowadays please?

Matt

#1 lore raw
Quoted 15 lines · Matt Killock

I am having trouble re-using scripts that worked in kernel 2.6.24 with a more recent 3.16.0 series kernel. The essence of what I am trying to do is this:

iptables mark all packets arriving from anywhere on interface 1 with '10'
iptables mark all packets arriving from anywhere on interface 2 with '20'

iptables DNAT incoming traffic on interface 1 on port 1111 to internal server via interface 3
iptables DNAT incoming traffic on interface 2 on port 1111 to internal server via interface 3

Quoted 8 lines

ip rule from all fwmark 10 table T1
ip rule from all fwmark 20 table T2

default gateway in table T1 is through interface 1 default gateway in table T2 is through interface 2

With the view to make everything that arrives on a particular interface leave via that interface. The above approach worked fine in kernel 2.6

I don't think so. You must mark packets from the server arriving from the server at interface 3, not packets arriving at interface 1 and 2. Packets arriving at interface 1 and 2 are all routed via interface 3, so they have no need for advanced routing.

Quoted 4 lines

but does not seem to work any more. With no default gateway in the main routing table, the packets arrive on the external interfaces but do not appear on the LAN interface, almost as if DNAT is having no effect at all.

Check the value of rp_filter for interface 1, interface 2 and all. Since some kernel version the logic has changed from AND to MAX.

Quoted 3 lines

One of the two DNAT rules works if I add a default gateway to the main routing table, but then it appears that the policy routing tables or firewall marks are ignored.

You must mark packets arriving from the server at interface 3. For this you must mark the incoming connections (CONNMARK) and transfer the connection mark to the packets arriving at interface 3.

Another method not requiring connection marking is to use the original destination address (-m conntrack --ctorigdst) to mark the packets.

#2 lore raw
Quoted 1 line · Pascal Hambourg

Check the value of rp_filter for interface 1, interface 2 and all.

Ah ha! Yes, the rp_filter was enabled for all those interfaces. Disabling it on all has made it work again! Hoorah!

Many thanks!

Matt