附 - 如何查看子网中的剩余IP

查看子网中所有已使用的IP

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

例如:

aws ec2 describe-network-interfaces --filters "Name=subnet-id,Values=subnet-3221874a" --query 'NetworkInterfaces[*].PrivateIpAddress' --region us-west-2 | jq
[
  "172.31.16.173",
  "172.31.28.181",
  "172.31.21.46",
  "172.31.31.114",
  "172.31.17.211"
]

查看子网中剩余可用IP数量

aws ec2 describe-subnets \
    --filters "Name=vpc-id,Values=vpc-acfeabd4" --region us-west-2   

返回结果中有个AvailableIpAddressCount字段:

image-20220903140713828