I'm trying to accomplish the following: I have a box with a service listening on a dummy interface (say 172.16.0.1), udp port 5555. Now what I'd like to do is to take packets that arrive on interfaces eth0 (22.214.171.124:5555) and eth1 (126.96.36.199:5555) and forward them to the service on the dummy interface, and have replies go back to clients out the same physical interface they came in. Clients must think they're talking to 188.8.131.52:5555 or 184.108.40.206:5555. I think I need a mix of iptables rules and packet marking, plus some iproute rules (if it's possible at all). What I tried is to catch packets coming in from eth0 and eth1, udp port 5555, and mark them with 1 and 2 respectively, and --save-mark in the connmark. Then I used a DNAT to 172.16.0.1. The service seems to be getting the packets. Now I'm not sure how to do the reverse. It seems that for packets originating from the box, you can't do anything before the routing decision, but that would be the place to restore the marks, and thus make a routing decision based on those. Here's what I have so far:
iptables -t mangle -A PREROUTING -d 220.127.116.11 -p udp --port 5555 -j MARK --set-mark 1 iptables -t mangle -A PREROUTING -d 18.104.22.168 -p udp --port 5555 -j MARK --set-mark 2 iptables -t mangle -A PREROUTING -d 22.214.171.124 -p udp --port 5555 -j CONNMARK --save-mark iptables -t mangle -A PREROUTING -d 126.96.36.199 -p udp --port 5555 -j CONNMARK --save-mark iptables -t nat -A PREROUTING -m mark --mark 1 -j DNAT --to-destination 172.16.0.1 iptables -t nat -A PREROUTING -m mark --mark 2 -j DNAT --to-destination 172.16.0.1 # What next?
As I said, I'm not even sure it can be done. To give a bit of background, it's an old OpenVPN installation that cannot be upgraded (otherwise I'd install a recent version that supports multihoming natively).
Thanks for any help.