Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iptables port redirection wont work for localhost

Tags:

iptables

I redirect port 80 to port 8000 via:

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

The other host can access my webserver via 80 port, but the redirection cannot work in local host when I access 127.0.0.1:80.

Can port direction work for loopback network adapter?

like image 908
xiaochen Avatar asked Oct 22 '22 20:10

xiaochen


1 Answers

The nat table is used for Network Address Translation, and is only used for external interfaces. You have to add the rule to a table that handles internal communication as well.

like image 190
Some programmer dude Avatar answered Dec 28 '22 09:12

Some programmer dude