Linux – How to forward port 80 to another port on the samemachine

linuxnetworkingport-forwarding

How can I forward requests coming in on port 80 to another port on the same linux machine?

I used to do this by changing nat.conf, but this machine that I'm using doesn't have NAT. What's the alternative?

Best Answer

You can accomplish the redirection with iptables:

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