I'm trying to setup a port forwarding from port 80
to port 8080
on my amazon linux ami machine.
I ran
$ sudo /sbin/iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
And verified the results:
$ sudo iptables --table nat --list
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
However requesting port 80
does not work:
$ wget http://localhost:80
--2017-09-25 08:51:27-- http://localhost/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:80... failed: Connection refused.
Whereas port 8080
works fine:
$ wget http://localhost:8080
--2017-09-25 08:51:39-- http://localhost:8080/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8080... connected.
How can I let port 80
be an alias for port 8080
?
Additional information:
$ cat /proc/sys/net/ipv4/ip_forward
1
$ sudo sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
error: "Input/output error" reading key "net.ipv6.conf.all.stable_secret"
error: "Input/output error" reading key "net.ipv6.conf.default.stable_secret"
error: "Input/output error" reading key "net.ipv6.conf.eth0.stable_secret"
error: "Input/output error" reading key "net.ipv6.conf.lo.stable_secret"
في الواقع ، كان إعادة توجيه المنفذ ساريًا ، لكنه لم يعمل مع المضيف المحلي
. ومع ذلك ، فإن الوصول إلى الميناء من الخارج كان يعمل بشكل مثالي.
ما زلت لا أعرف ، لماذا لم يعمل مع المضيف المحلي
ولكنه ليس مهمًا بالنسبة لي حاليًا.