大网数据广告活动
服务器运维问答

Can't open port on Amazon EC2 instance

· 52CE 我爱测

I have an API which I successfully hosted on Amazon AMI instance. I know that's for sure because I can use it locally using curl. Api hosted on port 8080. That's what I putted into cmd for open port: su iptables -I INPUT -p tcp -…

问题原文

原帖链接 · neustart47 · CC BY-SA 3.0

I have an API which I successfully hosted on Amazon AMI instance. I know that's for sure because I can use it locally using curl. Api hosted on port 8080.

That's what I putted into cmd for open port:

su
iptables -I INPUT -p tcp --dport 8080 -m state --state NEW -j ACCEPT
service iptables save
/etc/init.d/iptables restart

I turned the firewall off as well:

service iptables save
service iptables stop
chkconfig iptables off

That's how my out/in rules looks in AWS console:

And I still can't reach my app via server public IP from outside. Why that's happening?

UPDATE

Result for /sbin/iptables -L :

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

UPDATE 2

netstat -ltpn result:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      3941/uwsgi
tcp        0      0 0.0.0.0:58704               0.0.0.0:*                   LISTEN      -
tcp        0      0 :::45589                    :::*                        LISTEN      -
tcp        0      0 :::22                       :::*                        LISTEN      -
tcp        0      0 :::111                      :::*                        LISTEN      -

已采纳解答

原帖链接 · dsmsk80 · CC BY-SA 3.0

From the netstat output, it seems that your app is listening on loop-back interface only - 127.0.0.1:8080 and so you are not able to connect to it outside of the instance.

See e.g. ssh service - 0.0.0.0:22. This means the service is listening on "all network interfaces".

You need to reconfigure your application to make it listening not only on loop-back.

Another solution could be to add iptables DNAT rule so incoming requests are forwarded to the loop-back interface.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。