I have a cloud server running on Ubuntu 14.04 which is connected with an IPsec tunnel.
The server has a real interface with a public IP x.x.x.x and a virtual interface 172.16.100.1 All the traffic to the remote network should be routed over the virtual interface with IP 172.16.100.1 Therefore I have set up an routing an entry. This works correctly for all the traffic that is generated on that server.
route add -net 172.17.1.2/21 gw 172.16.100.1 dev eth0:1
But another requirement is that if the cloud server receives traffic on it's public IP with a specific port, that traffic should also be forwarded to the remote network. I tried that by adding an IP table entry:
iptables -t nat -A PREROUTING -p tcp --dport 45678 -j DNAT --to-destination 172.17.1.2:29871
but the problem is that it somehow ignores the routing configuration and just forwards the request with its source IP instead of using 172.16.x.x
Is that configuration even the right approach or am I completely wrong? What else do I have to configure to forward the traffic correctly?