【问题标题】:Retrieving the private IP addresses in a subnet in AWS在 AWS 的子网中检索私有 IP 地址
【发布时间】:2020-07-23 02:23:04
【问题描述】:

有没有一种简单的方法可以使用 AWS 命令​​行在特定子网中分配所有私有 IP?

我想输入子网 ID,即。 subnet-0ca0b01xxxxxxxxxx 并且输出应该是子网中分配的所有私有 IP 的列表。 谢谢。

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-vpc


    【解决方案1】:

    您可以使用以下命令:

    aws ec2 describe-instances --filters "Name=subnet-id,Values=**YourSubnetID**" --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text
    

    【讨论】:

      【解决方案2】:

      之前的解决方案只返回您的 EC2 实例的私有 IP,但是您的 RDS/ElastiCache 实例或任何其他使用私有 IP 的 AWS 资源呢?您实际上需要使用describe-network-interfaces 命令。

      这将返回单个或多个子网 ID 的所有私有 IP 地址:

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

      但是前面的命令也不适用于所有情况。例如,我在 AWS 运行多个 EKS 集群,Kubernetes 的 VPC CNI 插件可以为 single Elastic Network Interface 分配多个私有 IP 在这种情况下这是你需要使用的,它略有不同:

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

      【讨论】:

        猜你喜欢
        • 2016-03-16
        • 1970-01-01
        • 2017-05-05
        • 2021-05-22
        • 1970-01-01
        • 1970-01-01
        • 2016-03-24
        • 2012-11-28
        • 1970-01-01
        相关资源
        最近更新 更多