This question already has an answer here:
I have a situation where I need to communicate with an API that only allows connections from one particular IP.
So api.example.com accepts connections on port 443 from whitelisted-ip
I want to be able to connect from anywhere to whitelisted-ip port 443, and have it forward the packets to api.example.com on port 443, and send responses back to the connecting machine.
I assume there's some way of doing this similar to a transparent squid proxy, but I can't figure it out.
I tried following the examples here (http://www.tldp.org/HOWTO/TransparentProxy-6.html) using the statements below, but no success.
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 443 -j DNAT --to api.example.com:443 iptables -t nat -A POSTROUTING -o eth1 -d api.example.com -j SNAT --to whitelisted-ip
Any help would be appreciated.
I also tried the below, to no avail:
iptables -t nat -A PREROUTING -p tcp -d whitelisted-ip --dport 443 -j DNAT --to api.example.com:443 iptables -t nat -A POSTROUTING -p tcp -s api.example.com --sport 443 -j SNAT --to whitelisted-ip:443