EC2 安全组无法相互通信

EC2 security groups cannot communicate with each other

我有两个 AWS EC2 实例,它们试图通过自定义 TCP 端口相互通信。每个实例都有自己的安全组,但彼此之间不能通信。

这是我的设置:

EC2 实例 1

EC2 实例 2

新加坡出境规则:

问题

每当实例 1 尝试向 www.xxx.yyy.zzz:12345 发起 TCP 请求时,连接就会超时。

如果我将以下入站规则添加到实例 2 的 SG,它就可以正常工作:

总结

我需要实例 1 与实例 2 通信,不允许任何地方的流量访问端口 12345。有办法做到这一点吗?

您无法使用安全组作为传入源访问 public IP。

When you specify a security group as the source or destination for a rule, the rule affects all instances associated with the security group. Incoming traffic is allowed based on the private IP addresses of the instances that are associated with the source security group (and not the public IP or Elastic IP addresses). For more information about IP addresses, see Amazon EC2 Instance IP Addressing.

使用私有 IP 地址或使用 public IP 作为来源。

参考资料

Security Group Connection Tracking