Categories
AWS

How to Fix AWS EC2 Instances Can’t Ping Each Other?

When I deployed my nginx on an EC2 instance, I subsequently applied for a new EC2 instance to deploy an application (assuming the internal IP of the server hosting nginx is 172.16.100.1, and the new application server's internal IP is 172.16.100.2). After deploying my application on the new instance and configuring nginx to forward interfaces, when I restarted nginx, I found that the interface requests were not successful.

Why can't two EC2 instances ping each other?

On AWS, if two EC2 instances in the same region cannot ping each other, there could be several reasons for this issue. Here are some common reasons:

Security Group Configuration: Each EC2 instance is associated with one or more security groups, which act as virtual firewalls controlling inbound and outbound traffic. Ensure that your security group rules allow ICMP (ping) traffic. You need to add inbound rules in the security group configuration to permit ICMP traffic.

Network ACLs Configuration: Network ACLs operate at the subnet level and control traffic entering and exiting the subnet. Ensure that your network ACLs allow ICMP traffic to pass through. Check the network ACLs associated with your subnet.

Route Table Configuration: Ensure that the subnets where your two EC2 instances reside have correct route configurations to allow them to communicate with each other. Especially if your EC2 instances need to access the internet, ensure there is a properly configured internet gateway or NAT gateway.

Operating System Firewall Settings: The operating system running on your EC2 instances may have its own firewall settings. Ensure that the OS firewall allows ICMP traffic. For example, on Linux, check settings like iptables or firewalld.

Instance State: Ensure that both instances are in the running state. If one instance is stopped, it may not respond to ping requests.

Private IP Address Conflict: If two instances have the same private IP address, it can disrupt communication between them. Ensure that each instance has a unique private IP address.

How do I fix AWS EC2 instances can't ping each other?

My primary suspicion was the first reason, which is security group configuration. Therefore, I checked the security group used by my servers and found that both servers were using the same security group.

If the Nginx server and the application server are using the same security group, you only need to configure the rule once in that security group. Since security group rules are bidirectional, rules set within the same security group apply to both inbound and outbound traffic. In this case, ensure that the security group allows traffic initiated by the Nginx server to access port 8081 on the application server.

Here are the steps I followed:

1. Log in to the AWS Management Console and navigate to the EC2 Console

2. Select "Security Groups" and find your security group

3. In the detailed information page of the security group, select the "Inbound" tab

4. Add a rule, select the allowed traffic type (protocol) (e.g., "HTTP (80)" or "HTTPS (443)")

5. Enter the source IP address range (can be the IP address of the Nginx server) and set the destination port to 8081

6. Save the rule

After configuring this, the security group rule applies to traffic initiated by the Nginx server and the response from the application server, eliminating the need to configure rules again in the application server's security group.

If you encounter an error when configuring the Nginx IP, such as "must specify a CIDR block, security group ID, or prefix list," you can use CIDR (Classless Inter-Domain Routing) notation and set the subnet mask to 32. In CIDR notation, /32 denotes a single IP address, such as 172.16.100.1/32.

With these configurations in place, I tested again by running telnet 172.16.100.2 8081 from the Nginx server and confirmed it was successful, indicating that the issue was resolved.

Summary

I resolved the issue of EC2 instances not being able to ping each other by configuring inbound rules in the security group.

By Jaxon Tisdale

I am Jaxon Tisdale. I will share you with my experience in Network, AWS, and databases.

Leave a Reply

Your email address will not be published. Required fields are marked *