I need to redirect all tcp traffic coming out of local programs to the interface that is able to connect to a proxy server.
According to this picture
I need to add rules to the OUTPUT
chain, but almost everywhere said that I need to add rules like this
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080
Could someone explain why ? As far as I can understand this rule is applied for all incoming traffic but not outgoing traffic ?
I have tried something like that
iptables -t nat -A OUTPUT -p tcp --jump DNAT --to-destination 192.168.56.1:8080
But this doesn't work It shows me that HTTP request is invalid.
Could someone please explain how to forward all traffic through proxy and explain why a specific table/chain is used ?