AWS: List of assigned IPs in subnet

scagnetti picture scagnetti · Apr 26, 2018 · Viewed 7.6k times · Source

Is there a way to get a list of all assigned IPs in an AWS subnet? Furthermore, if there is a way to see the associated (AW)Services? That would be incredibly helpful as well. Thanks!

EDIT:

All assigned private IPs in a private AWS Subnet (which are retained regardless of instance state). Any means of obtaining this information will do. I am most familiar with AWS CLI, boto/boto3 and the console.

The list would include all avail per CIDR block definition except for 5 addresses:

Answer

helloV picture helloV · Apr 26, 2018
aws ec2 describe-instances --filters "Name=subnet-id,Values=subnet-12345678" --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text
  • Use describe-instances
  • Query by subnet-id
  • Filter the results by PrivateIpAddress

Using @Michael - sqlbot's suggestion:

aws ec2 describe-network-interfaces --filters "Name=subnet-id,Values=subnet-12345678" --query 'NetworkInterfaces[*].PrivateIpAddress'