How to Enable Ping in AWS EC2 Instance
Recently many of you have been asking me that you are unable to ping EC2 instance after launching it. Well, you might already know that due to virtual firewall or security group, by default, no inbound traffic is allowed. Therefore it is so obvious for ping to not work.
However, this doesn’t mean that you can not make it work.
Afterall, the security group is there for your instance’s security so that you can manage traffic into your EC2 machine. Which means, you can actually configure your security group to allow ping traffic.
Let’s learn “how” in this post 🙂
This post will help you learn how to enable ping in AWS EC2 instance.
Basic Overview of Ping:
Do you Know that “ping is one of the most used networking command”
Ping is a very basic command line utility that allows you to know that a remote host exists and is up and running or reachable over internet . In other words, if I say, ping is the simplest way to know that a host is running.
This is how a basic ping command looks like-
Ping works on ICMP or Internet Control Message Protocol. It works by sending a ICMP Echo Request to your EC2 instance and waits for Echo Reply from it. The reply has details for you to understand connectivity details
What happens when you ping your EC2 instance right after launch
You might already have guessed that by now. As by default, security group doesn’t allow inbound ICMP traffic so your ping request to your EC2 instance is gonna fail.
Let’s prove that by hands on-
Launch an EC2 instance using previous tutorial. Link is given below-
After your instance is up and running, Click on your instance id to go to instance details screen. Grab the public IP or pubic DNS from there and keep it handy as we will fire a ping command from our local system.
Open terminal or command line in your system and fire ping command.
Note: Please make sure to use your own EC2 instance’s public IP
As obvious as it sounds, the ping request timed out. Most of the time when you see timeout in AWS, you need to double check your security group 🙂
So, we proved that we need to allow ping from our security group.
Note: Pease note that you only needs to add an inbound rule for Echo Request and no need to add outbound rule for Echo Reply. As, security groups are stateful and once inbound traffic is allowed, outbound is allowed as well.
Steps to add an Inbound rule to an EC2 instance Security Group
Chhose Security Group of Your Instance
Click on Instance ID and you will be in instance details page
Open Security tab and click on the Security groups link
Scroll Down and Click Edit inbound rules
Click Add Rule
Details of rule will be like below.
- Type: Custom ICMP rule
- Protocol: Echo Request
- Port: N/A
- Source: your choice
Source: Can be your IP(My IP option ) or Anywhere Ipv4 , Anywhere Ipv6 or Custom
I have choosen My IP option so that ping is only allowed from my IP. But if you need to choose from everwhere or custom IP List, feel free to do so.
Please make sure that protocol is Echo Request and not Echo Reply This is a very very common mistake people do. As a resut, they are unable to ping EC2 instance. So watch out and don’t make the same mistake.
After double checking the details, click Save rules
Once you save, you get success message like below.
Since security group allows ICMP now, our expectation is that things should work fine now. Let’s verify that.
Verify Ping Again on Your Instance
And this time it worked all good.
Congratulations !!! You made it 🙂
In this post, we learnt “How to Enable Ping in AWS EC2 Instance“. We saw that, in order for us, to be able to ping an EC2 instance, the instance security group must allow ICMP traffic and Echo Request protocol. You don’t need to chhose a port. Also source can be any IP or security group.
We also verified ping request and response before and after adding the security group inbound rule. We verified that adding an inbound rule makes ping requests to succeed.
Hope that was clear. Feel free to let me know in case of questions
Enjoyed the content?
Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.
Well, that was my take on “ How to Enable Ping in AWS EC2 Instance “. Please feel free to share your feedback.
If you liked reading my post, you can motivate me by-
- Adding a comment below on what you liked and what can be improved.
- Follow us on
- Share this post with your friends and colleagues.
- Create an EC2 instance in an existing VPC using CloudFormation
- Attach an IAM Role to an EC2 instance using CloudFormation
- AWS EC2 Instance Purchasing Options: All You Need to Know
- Attach Elastic IP to Your EC2 Instance
- How to Install Apache Web Server on EC2 Linux
- How to use User Data Script to Install Apache Web Server on EC2
- Execute EC2 User Data Scripts using CloudFormation