Redirect port 80 to 8080 using iptables

on your pi or your linux installation, you should probably have something called iptables

sometimes you don’t want to run say, nodejs, as root. but you can’t make it listen to ports lower than 1024 without being root.

in that case just redirect all traffic on port 80 to something like 8080. then run your node app to listen to port 8080 and you are good to go!

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

Leave a Reply

Your email address will not be published. Required fields are marked *