You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

AWS VPC公/私有子网实例可自Ping但无法互Ping求助

Troubleshooting Ping Failure Between AWS EC2 Instances in Public/Private Subnets

Let’s break down the most likely reasons your DB (private subnet) and Web (public subnet) instances can’t ping each other, even with SSH access enabled and a shared route table:

1. Security Group Rules Are Missing ICMP Permissions

SSH uses TCP port 22, but ping relies on ICMP (Internet Control Message Protocol)—specifically Echo Request (Type 8) and Echo Reply (Type 0) packets. Your current SSH rules don’t cover this traffic type.

  • For your DB server’s security group: Add an inbound rule allowing ICMP Echo Request from your Web server’s security group (or its private IP range).
  • For your Web server’s security group: Add an inbound rule allowing ICMP Echo Reply from your DB server’s security group (or its private IP range).
    • Pro tip: Instead of hardcoding IPs, reference the other instance’s security group directly (e.g., sg-xxxxxx) for better scalability and security.

2. Network ACLs Are Blocking ICMP Traffic

Network ACLs act as a subnet-level firewall, and unlike security groups, they’re stateless—you need to explicitly allow both inbound and outbound traffic for ICMP:

  • Check the network ACL attached to both subnets:
    • Inbound rules: Allow ICMP Type 8 (Echo Request) from your VPC’s full CIDR range.
    • Outbound rules: Allow ICMP Type 0 (Echo Reply) to your VPC’s full CIDR range.
  • Note: If you modified the default network ACL (which allows all traffic by default), double-check that you didn’t accidentally block ICMP packets.

3. Route Table Missing Local VPC Route

Even though you’re using the same route table, ensure it includes the local route for your VPC’s CIDR block (e.g., 10.0.0.0/16). This route is critical—it allows instances within the same VPC to communicate directly with each other without routing through external gateways.

  • If this route was deleted by mistake, add it back with the target set to local.

4. Instance-Level Firewall Blocking ICMP

Your EC2 instances might have OS-level firewalls that block ping requests, independent of AWS security groups:

  • For Linux instances:
    • Run sudo iptables -L to check for rules that reject or drop ICMP traffic.
    • If using firewalld, run sudo firewall-cmd --list-all to verify ICMP is allowed. You can enable ping access with sudo firewall-cmd --add-icmp-type=echo-request --permanent && sudo firewall-cmd --reload.
  • For Windows instances:
    • Open Windows Defender Firewall and confirm the "File and Printer Sharing (Echo Request - ICMPv4-In)" rule is enabled for private networks.

5. Verify VPC and Subnet CIDR Configuration

Double-check that both subnets are part of the same VPC, and their CIDR ranges are non-overlapping and fully within the VPC’s CIDR block. For example, if your VPC is 10.0.0.0/16, a valid setup might be a public subnet 10.0.1.0/24 and private subnet 10.0.2.0/24—mismatched or overlapping ranges can break internal routing.

Start with checking security groups first—this is the most common culprit when SSH works but ping fails!

内容的提问来源于stack exchange,提问作者fatima

火山引擎 最新活动