Get the public ip address of your EC2 instance quickly


In this guide, we’ll explore how to list public and private IP Addresses of your EC2 instances using the AWS Command Line Interface (CLI). Let’s dive into the details.

To find the public IP addresses of your EC2 instances with the AWS CLI, run the command aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId, PublicIpAddress]' --output table and it will return a table with a column containing the InstanceID and another column with the attached public IP address.

In the blog post below you’ll find the detailed steps on how to find your IP Addresses that are attached to your EC instances.

Get the Public IP Addresses of your EC2 Instances Using AWS CLI

Before you can get the public or private IP address if your Amazon EC2 instances using the AWS CLI, make sure to log in to the specified AWS CLI profile. Otherwise, you can’t run any AWS CLI commands on your AWS account.

Once you’ve signed in into your AWS CLI, you can then list the public IP address along with the corresponding instance IDs using the following command:

aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, PublicIpAddress]' --output table

This will return a table with a column containing the InstanceID and another column with the corresponding public IP address.

➜ aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, PublicIpAddress]' --output table

------------------------------------------
|            DescribeInstances           |
+----------------------+-----------------+
|  i-02d9aafce03c4e642 |  3.71.189.174   |
|  i-0e7cae0f9671f4198 |  3.121.183.144  |
|  i-064e5b7eea2143a58 |  3.120.190.247  |
+----------------------+-----------------+

Optional: List Private IP Addresses of EC2 Instances Using AWS CLI

Private IP addresses are used for communication within the Amazon VPC. Here’s how to list them with the following command:

aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, PrivateIpAddress]' --output table

This will return a table with a column containing the InstanceID and another column with the corresponding private IP address.

➜ aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, PrivateIpAddress]' --output table
----------------------------------------
|           DescribeInstances          |
+----------------------+---------------+
|  i-02d9aafce03c4e642 |  10.0.10.217  |
|  i-0e7cae0f9671f4198 |  10.0.7.21    |
|  i-064e5b7eea2143a58 |  10.0.14.200  |
+----------------------+---------------+

Conclusion

Managing IP addresses is a common task in AWS, and the AWS CLI provides powerful tools to list and manipulate these addresses. In this guide, we’ve covered how to list public and private IP addresses of your EC2 instances.

Whether you’re an administrator managing a large fleet of instances or a developer troubleshooting a single instance, these commands provide a quick and efficient way to access the information you need.


Want to join us? Join for tips, strategies, and resources that I use in my solo cloud agency to build well-architected, resilient, and cost-optimized AWS solutions on AWS.

Join 1k+ AWS Cloud enthusiasts
Loved by engineers worldwide


Danny Steenman

A Senior AWS Cloud Engineer with over 9 years of experience migrating workloads from on-premises to AWS Cloud.

I have helped companies of all sizes shape their cloud adoption strategies, optimizing operational efficiency, reducing costs, and improving organizational agility.

Connect with me today to discuss your cloud aspirations, and let’s work together to transform your business by leveraging the power of AWS Cloud.

I need help with..
stacked cubes
Improving or managing my CDK App.Maximize the potential of your AWS CDK app by leveraging the expertise of a seasoned CDK professional.
Reducing AWS Costs.We can start by doing a thorough assessment of your current AWS infrastructure, identifying areas with potential for cost reduction and efficiency improvement.
Verifying if my infrastructure is reliable and efficient.We’ve created a comprehensive AWS Operations Checklist that you can utilize to quickly verify if your AWS Resources are set up reliably and efficiently.