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.
Table of Contents
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.