xiaochen
xiaochen

Reputation: 1305

iptables port redirection wont work for localhost

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?

Upvotes: 5

Views: 7110

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409176

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.

Upvotes: 3

Related Questions