【问题标题】:AWS Port in Security Group but Can't Connect安全组中的 AWS 端口但无法连接
【发布时间】:2014-04-14 18:51:49
【问题描述】:

我有一个包含 80、443、22 和 8089 的安全组。

Ports  Protocol   Source    security-group
22      tcp      0.0.0/0      [check]
8089    tcp      0.0.0/0      [check]
80      tcp      0.0.0/0      [check]
443     tcp      0.0.0/0      [check]

但是,当我使用 Python 程序测试连接时,我写道:

import socket
import sys

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
p = sys.argv[1]
try:
    s.connect(('public-dns', int(p)))
    print 'Port ' + str(p) + ' is reachable'
except socket.error as e:
    print 'Error on connect: %s' % e
s.close()

但是,除了 8089 之外,我对所有端口都很满意:

python test.py 80
Port 80 is reachable
python test.py 22
Port 22 is reachable
python test.py 443
Port 443 is reachable
python test.py 8089
Error on connect: [Errno 61] Connection refused

【问题讨论】:

  • 我也有同样的问题。我已经在安全组中启用了我的端口(9966),验证了监听进程是否正常工作,从服务器的角度使用“localhost”进行了本地测试,验证了 ufw 处于非活动状态 - 仍然无法从其他机器访问到那个港口。

标签: amazon-web-services port


【解决方案1】:

您能够通过 localhost (127.0.0.1) 而不是外部成功连接的原因是因为您的服务器应用程序仅在 localhost 适配器上侦听。这意味着只有源自实例本身的连接才能连接到该进程。

要更正此问题,您需要将应用程序配置为侦听接口的本地 IP 地址或所有接口 (0.0.0.0)。

这鞋说错了(听127...):

~ $ sudo netstat -tulpn | grep 9966
tcp        0      0 127.0.0.1:9966          0.0.0.0:*               LISTEN      4961/python 

这是正常工作(使用所有接口):

~ $ sudo netstat -tulpn | grep 9966
tcp        0      0 0.0.0.0:9966            0.0.0.0:*               LISTEN      5205/python

【讨论】:

    【解决方案2】:

    除了 AWS 安全组(看起来您已正确设置)之外,您还需要确保如果主机上有内部防火墙,它也对所有指定的端口开放。

    【讨论】:

      猜你喜欢
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 2017-04-20
      相关资源
      最近更新 更多