Ubuntu – Redirect port 80 to 8080 and make it work on local machine

iptablesport-forwarding

I redirected traffic for port 80 to 8080 on my machine with

sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 8080

It works fine for all the world except my own machine. I am a developer and I need to redirect port 80 to 8080 for myself.

My IP is 192.168.0.111

My web server runs on port 8080

I wish to open website from http://192.168.0.111/ instead of http://192.168.0.111:8080/ from same machine where server runs.

Best Answer

You need to use the OUTPUT chain as the packets meant for the loopback interface do not pass via the PREROUTING chain. The following should work; run as root:

iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8080
Related Question