Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

ping to an EC2 instance times out, but SSH and the website work

ErrorRequest timed out.

Short answer

Ping is ICMP traffic, and a security group that allows SSH or HTTP does not allow it. Add an inbound ICMP Echo Request rule for your address. Use an ICMPv6 rule for ping6, and an outbound rule if the instance is the one pinging. Firewalls on the path can also drop ICMP.

  • Applies to Amazon EC2, VPC security groups, AWS CLI v2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the rules of the instance's security group and look for an ICMP line. If there is none, the first cause below is yours.

    aws ec2 describe-security-groups --group-ids sg-1234567890abcdef0
  2. 2Match what you see, then jump to its fix

    1. 1ping times out while TCP services on the same instance answerNo inbound ICMP Echo Request ruleFix
    2. 2ping to the IPv4 address works, ping6 to the IPv6 address times outYou are using ping6 but only an IPv4 ICMP rule existsFix
    3. 3Pinging from the instance to another host fails, while pinging into the instance worksThe instance cannot send ping out: outbound rule missingFix
    4. 4The rule is there and still no reply, or replies are lost along the pathA firewall, or network latency, between you and the instanceFix

What does the error look like?

  • Request timed out.
  • 100% packet loss

Cause 1 of 4

No inbound ICMP Echo Request rule

1Check

The ping command is ICMP. AWS says inbound rules must allow the ICMP Echo Request message from all sources, or from the computer you ping from. A TCP rule for port 22 or 80 does not cover it.

aws ec2 describe-security-groups --group-ids sg-1234567890abcdef0

2Fix

Add an inbound ICMP rule. In the console choose Custom ICMP - IPv4 with Echo request, and set the source to your own public IPv4 address rather than anywhere. With the CLI, ICMP type -1 and code -1 means all ICMP types and codes.

aws ec2 authorize-security-group-ingress \
  --group-id sg-1234567890abcdef0 \
  --ip-permissions 'IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges=[{CidrIp=203.0.113.25/32}]'

3Verify

ping the instance's public IPv4 address or DNS name.

ping -c 4 ec2-203-0-113-25.compute-1.amazonaws.com

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 4

You are using ping6 but only an IPv4 ICMP rule exists

1Check

IPv6 ping needs its own rule. The EC2 docs list an inbound All ICMP - IPv6 rule (protocol IPv6 ICMP, number 58) for ping6.

aws ec2 describe-security-groups --group-ids sg-1234567890abcdef0

2Fix

Add the ICMPv6 inbound rule for your IPv6 address or range.

aws ec2 authorize-security-group-ingress \
  --group-id sg-1234567890abcdef0 \
  --ip-permissions 'IpProtocol=icmpv6,Ipv6Ranges=[{CidrIpv6=2001:db8:1234:1a00::/64}]'

3Verify

ping6 the instance's IPv6 address.

ping6 -c 4 2001:db8:1234:1a00::25

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 3 of 4

The instance cannot send ping out: outbound rule missing

1Check

If the instance is the one issuing ping, the outbound rules must allow ICMP Echo Request to all destinations or to the host you target. This matters when someone removed the default allow-all outbound rule.

aws ec2 describe-security-groups --group-ids sg-1234567890abcdef0

2Fix

Add an outbound ICMP Echo Request rule for the destination you want to test. In the console, open the security group, choose Edit outbound rules, and add Custom ICMP - IPv4 with Echo request.

# EC2 console > Security groups > your group > Outbound rules > Edit outbound rules

3Verify

Run ping from the instance to that host.

ping -c 4 198.51.100.7

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 4 of 4

A firewall, or network latency, between you and the instance

1Check

The AWS page says ping can also be blocked by a firewall, or time out from network latency or hardware problems. Test from a second network (for example a phone hotspot) to see whether your own network drops ICMP.

ping -c 4 ec2-203-0-113-25.compute-1.amazonaws.com

2Fix

Ask the owner of the corporate or home network to allow ICMP, or test from a network that does.

# ask the network owner to allow ICMP echo, or check the firewall running on the instance

3Verify

A reply arrives from the second network.

ping -c 4 ec2-203-0-113-25.compute-1.amazonaws.com

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Treat ping as optional: test a real service port (22, 80, 443) when you want to know whether the app is reachable.
  • Open ICMP only to your own address range, not to 0.0.0.0/0, unless the instance has a reason to answer everyone.
  • Keep the security group rules in infrastructure code so a missing ICMP rule shows in review.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

Apache has a certificate, but https:// does not open

No line with :443 in the output of ss -ltnp

HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.

4 causes, each with a fix

Servers

AWS CLI says you must specify a region

You must specify a region. You can also configure your region by running "aws configure".

The AWS CLI sends every request to one region and has none to use.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.