I'm trying to forward the local port 80 to the local port 9080. Basically this works if I set
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 9080
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 9080
but what happens then is that I cannot access external websites from this server. Whenever I try to open a website my requests end up on my local machine.
How can I tell iptables to forward only requests to any of my local ip addresses?
You need to change the 2nd rule to read:
In this case, you will redirect the requests generated by your local machine and destined also to your local machine only. So, remote connections will not be affected.