I have a host with ip $HOST_IP
which runs an HTTP server on port 8080. There is a transparent proxy server running on port 9000 on host with IP $PROXY_SERVICE_IP
.
I'm trying to forward traffic from the original host to the proxy server. I have these two iptables
rules:
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination $PROXY_SERVICE_IP:9000
iptables -t nat -A POSTROUTING -p tcp -d $PROXY_SERVICE_IP --dport 9000 -j SNAT --to-source $HOST_IP
They work great, I get the packet to the proxy server.
The problem: The proxy server tries to resolve the original request, by make the request to the host, but that traffic is redirected to the proxy, so it ends up in a loop.
What iptables
rule could I use to prevent this? When the proxy server makes a request to the host disable the forwarding? I tried to add ! -s $PROXY_SERVICE_IP
to the rules above, but it didn't work.