I am trying to forward traffic from one server to another, while keeping the origin requestor IP. Therefor I cannot use SNAT or MASQUERADE.
SERVER A:
Public IP: 111.111.111.111
Private IP: 10.0.0.1
SERVER B:
Public IP: 222.222.222.222
Private IP: 10.0.0.2
I want to forward traffic från Server A (111.111.111.111) to Server B (10.0.0.2).
This works fine:
iptables -t nat -A PREROUTING -d 111.111.111.111 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.2:80
iptables -t nat -A POSTROUTING -j MASQUERADE
However, because I am using MASQUERADE in this case, the destination server (10.0.0.2) sees all traffic as it would be comming from 111.111.111.111, i.e apache-logs and others are showing all requests as they are comming from 111.111.111.111
How can I setup this instead, so that the origin source IP-address is kept, like a home-router is doing it when using port forwarding.
I assume I need to setup a "route" somehow, so that the outgoing traffic from 10.0.0.2 goes out through Server A and not trying to respond on Server B's public IP?