简体   繁体   English

如何在我的 GCP 组织中获取所有外部 IP 地址?

[英]How can I get all External IP Addresses in my GCP organization?

I would like to get ALL external IP addresses in my GCP Organization.我想在我的 GCP 组织中获取所有外部 IP 地址。 This information seems to be available in the GCP Console under VPC.network > External IP Addresses, but I can't seem to find an API or way to export this information.此信息似乎在 VPC.network > 外部 IP 地址下的 GCP 控制台中可用,但我似乎找不到 API 或导出此信息的方法。

I've tried the GCLOUD command line tool but it only lists STATIC ip addresses.我试过 GCLOUD 命令行工具,但它只列出了 STATIC ip 地址。 I also want ephemeral addresses: gcloud compute addresses list我还想要临时地址: gcloud compute addresses list

The Go GCP Compute API does the same. Go GCP 计算 API 做同样的事情。

There are two types of public (external) IP addresses in Google Cloud: regional and global. GCP 中有两种类型的公共(外部)IP 地址:区域性和全球性。

The following commands use the Windows syntax.以下命令使用 Windows 语法。 Modify each command for the project ID and region list.修改项目 ID 和区域列表的每个命令。

This command will list the regional addresses for the specified regions:此命令将列出指定区域的区域地址:

gcloud compute addresses list  --project development --filter="region:( us-west1, us-west2 )"

This command will list the global addresses:此命令将列出全局地址:

gcloud compute addresses list --global --project development

Note that this must be repeated for each project.请注意,必须为每个项目重复此操作。 There are no options for organizations.组织没有选择。

To list the projects that your credentials have rights to:要列出您的凭据有权执行的项目:

gcloud projects list

This does not mean that all projects on this list are part of your organization.这并不意味着此列表中的所有项目都是您组织的一部分。 Credentials can be added as member accounts in projects outside your organization.凭证可以作为成员帐户添加到组织外的项目中。

This does not mean that all projects in your organization are listed.这并不意味着列出了您组织中的所有项目。 Only the ones with permissions to list/access the projects.只有有权列出/访问项目的人。 Your organization could be using Folders.您的组织可能正在使用文件夹。

The following link is for the API:以下链接适用于 API:

Method: addresses.list 方法:addresses.list

To achieve this goal, you can use something like this为了实现这个目标,你可以使用这样的东西

PROJECTS=$(gcloud projects list --format="value(name)")

for project in $PROJECTS
do
    if [[ $(gcloud services list --project $project --format="table(NAME)" | sed '1d') =~ "compute.googleapis.com" ]];then
       echo $project
       gcloud compute addresses list --project $project --global
    fi
done

As was mentioned in previous responses, there is no easy way to get that information.正如在之前的回复中提到的,没有简单的方法来获取这些信息。

I tried with some commands in my own project and I can list all the external ephemeral IPs on my instances:我在自己的项目中尝试了一些命令,我​​可以列出我的实例上的所有外部临时 IP:

gcloud compute instances describe INTANCE_NAME --format='get(networkInterfaces[0].accessConfigs[0].natIP)' --zone ZONE
gcloud compute instances list --format='table(EXTERNAL_IP)'

Also I found another public tracker where they are requesting almost the same that you mentioned, may you can take a look and comment something there.我还发现了另一个公共跟踪器,他们的要求与您提到的几乎相同,您可以查看并评论那里的内容。

#!/bin/bash -e

PROJECTS=$(gcloud projects list --format="value(project_id)" | sort | uniq)

for project in $PROJECTS
do
    if [[ $(gcloud services list --project $project --format="table(NAME)" | sed '1d') =~ "compute.googleapis.com" ]];then
       echo $project
       gcloud compute addresses list --project $project
       gcloud compute addresses list --project $project --global
    fi
done

Google Cloud uses a wide range of IP addresses that changes overtime. Google Cloud 使用随时间变化的各种 IP 地址。 According to this link , the nearest way is using DNS lookup commands ( nslookup , dig , or host ) to manually scrub through a number of addresses and compare against the static addresses and pick out the ephemeral addresses.根据此链接,最近的方法是使用 DNS 查找命令( nslookupdighost )手动清理多个地址并与静态地址进行比较并挑选出临时地址。

Having said that, there is a public tracker for this feature which is being evaluated if a flag can be added to the command gcloud compute addresses list to list the ephemeral IPs: https://issuetracker.google.com/119178618话虽如此,如果可以将标志添加到命令gcloud compute addresses list以列出临时 IP,则正在评估此功能的公共跟踪器: https : gcloud compute addresses list

Here is another related topic: https://stackoverflow.com/a/53650099这是另一个相关主题: https : //stackoverflow.com/a/53650099

I have managed to get the Ephemeral IP addresses by running the following commands on Linux.通过在 Linux 上运行以下命令,我设法获得了Ephemeral IP 地址。

GCP console shows (VPC network -> External IP addresses):
    - XX.XX.XX.XX us-west2 Ephemeral
    vmnumber1 XX.XX.XX.XX us-west2 Static
    vmnumber2 XX.XX.XX.XX us-west2 Static

These are the Static Public IPs (gcloud does not show Ephemeral IP addresses)
    gcloud --project your_project_name compute addresses list --format="value(ADDRESS)" | sort | tee -a static_public_ips
        XX.XX.XX.XX
        XX.XX.XX.XX

These are the Public IPs assigned to instances, it may include (Static and Ephemeral IP addresses)
    gcloud --project your_project_name compute instances list --filter="EXTERNAL_IP!=NULL" --format="value(EXTERNAL_IP)" | sort | tee -a static_public_ips_assigned
        XX.XX.XX.XX
        XX.XX.XX.XX

Then we can compare the two files, but we want the IPs that are not in `static_public_ips` which are the `Ephemeral` ones.
    diff -u static_public_ips static_public_ips_assigned | sed -n '/^+[^+]/ s/^+//p'
        XX.XX.XX.XX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud/GCP - 查找 GCP 实例使用的所有临时外部 IP 地址 - Google Cloud/GCP - Find all Ephemeral external IP addresses in use by GCP instrances 如何将 static 外部地址 IP 附加到 GCP Cloud TPU 虚拟机? - How can I attach a static external IP address with a GCP Cloud TPU VM? 如何指定 GCP 数据流的 IP 号? - How can I specify the IP number of GCP's Dataflow? 我如何导出(到文件)所有在 GCP 组织中每个项目具有特定角色的人? - How do I export(to a file) all people with a certain role per project in an organization in GCP? GCP-IAM - 如何授予对组织中所有服务帐户的访问权限? - GCP-IAM - How to grant access to all service account in organization? 如何列出 GCP 中属于特定组织的所有项目 - How to list all projects in GCP that belongs to a specific organization 如何在 Prometheus 中从我的 GCP 组织导出 SLO? - How to export SLO's from my GCP organization in Prometheus? 如何从 Terraform 中的 GCP 集群中删除外部 IP - How to remove external IP from GCP cluster in Terraform 如何在运行时从 Go 代码获取 pod 外部 IP - How can I get pod external IP from Go code at runtime Google CA 是否接受 IP 地址作为 SubjectAltNames,我该如何 go 关于这个? - Does Google CA accept IP addresses as SubjectAltNames and how can I go about this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM