Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS: List of assigned IPs in subnet

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:

  • 1 for subnet address
  • 1 for broadcast
  • AWS reserves the first 3 available IP addresses for each subnet
like image 501
scagnetti Avatar asked Apr 26 '18 16:04

scagnetti


1 Answers

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'
like image 143
helloV Avatar answered Oct 08 '22 07:10

helloV