How to open traffic between 2-Ec2 instances via internal private IPs

0

I have 2 ec2 instances that are needed to communicate as backend servers. They are both attached to the same security group which has a inbound rule allowing for all ports on the VPC's CIDR range. So the CIDR range is 172.31.0.0/32 for all ports.

The program is that when I ping instance 1 from instance 2 using the internal IP address, the ping fails. I'm not sure why that fails. Any help would be great.

2 Answers
1

The /32 CIDR range only allows a single host in the range. VPC CIDR ranges are typically between /16 and /24. If you want all hosts associated to the security group to communicate with each other on all ports and protocols you will need to expand the CIDR range to match the CIDR of your VPC (i.e. something like 172.31.0.0/16) or you can self reference the security group id as the source in the rule rather than a CIDR range. See this documentation.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/security-group-rules-reference.html#sg-rules-other-instances

profile pictureAWS
EXPERT
answered a year ago
0

/32 mean single IP address. 172.31.0.0/32 won't much with any EC2 instance. You have to create rule for each server. Ex: 172.31.10.5/32 First EC2 172.31.10.6/32 Second EC2

answered a year ago
  • What if I know that all the EC2s will be on the same VPC and will all have private IPs within the range of 172.31.0.0? Is there not a way to specify everything within that range?

  • Please see my answer below for a link to AWS docs but the short of it is you need the rule CIDR range to match your VPC CIDR. Assuming your VPC is defined as 172.31.0.0/16 this is what your rule should reflect. Or you can self reference the security group and not deal with CIDR ranges at all.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions