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.
You need to use the
OUTPUT
chain as the packets meant for the loopback interface do not pass via thePREROUTING
chain. The following should work; run asroot
:Simple just use iptables allowing both port 80 and 8080 then redirect 80 to 8080 make sure you are assigning to the correct nic.. in example I use eth0
This worked for me.
Instead of the
iptables
, You could try:sudo ssh -gL 80:127.0.0.1:8080 localhost
i have been trying very hard to forward a port from 8080 to 80 , but i am unable to find a right solution but then this worked for me https://askubuntu.com/a/579540/1611784
iptables -t nat -A OUTPUT -o lo -p tcp --dport 8080 -j REDIRECT --to-port 80