Question: I want to route, using iptables, all the OUTGOING HTTP requests from my machine to mitmdump running on the same machine, and then to the original destination.

I'm using this iptables rule but it seems that it doesn't work:

```
$ sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:8080

```

Can somebody explain me why it isn't the right solution and what is the correct way to accomplish this?

Answer: 
Solved using the owner module of iptables:

```
iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner ! --uid-owner 0 -j DNAT --to 127.0.0.1:8080

```

And then launch mitmdump as root. Or better create a new user for mitmdump and replace 0 with the uid of the user.
In accordance with <http://docs.mitmproxy.org/en/stable/transparent/linux.html> , you want to add those rules to the PREROUTING table:

```
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080

```