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.
Below you'll find the steps to find the IP addresses attached to your EC2 instances.
Get the Public IP Addresses of your EC2 Instances Using AWS CLI
Before you can get the public or private IP address of your Amazon EC2 instances, 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. The AWS CLI can list them for you. In this guide, we've covered how to list public and private IP addresses of your EC2 instances.
Whether you manage a large fleet or troubleshoot a single instance, these commands give you the information you need quickly.
Frequently Asked Questions
How do I get the public IP address of an EC2 instance with the AWS CLI?
How do I list the private IP addresses of my EC2 instances?
Do I need to sign in before running these commands?
Why does an instance show no public IP address?
Next step