如何找到Google Cloud VM的外部IP()

你正在GCP服务器中定位外部IP地址。
你是否正在一个项目中需要检索相应VM实例的外部(Internet /公共)IP以进行应用?
好消息–你可以快速获得它们。
我确定你会尝试运行ifconfig命令。而且, 你可能会注意到结果仅包含内部IP。
GCP和AWS都有友好的Web界面, 你可以在其中看到公共IP, 但是如果你需要将它们直接放在服务器上, 则以下命令将为你提供帮助。
在GCP VM上获取外部IP我知道有两种可能的方法。第一个是使用gcloud命令。

gcloud compute addresses list

上面的命令将显示所有项目IP。登录虚拟机时, 对于故障排除或快速查看很有用。
例如:
[email  protected]:~# gcloud compute addresses listNAMEADDRESS/RANGETYPEPURPOSENETWORKREGIONSUBNETSTATUSinstance-1xx.xx.xx.xxus-west1IN_USEgeekflare-nexusxx.xx.xx.xxINTERNALGCE_ENDPOINTus-west1defaultIN_USEgeekflarexx.xx.xx.xxus-west1IN_USEgeekflare-toolsxx.xx.xx.xxus-west1IN_USE[email  protected]:~#

第二个是使用curl命令对元数据进行处理。
curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip

注意:如果你有多个网络接口, 则必须在网络接口更改为1或2后将其更改为0。
元数据功能强大;你可以检索许多指标。
[email  protected]:~# curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/attributes/cpu-platformdescriptiondisks/guest-attributes/hostnameidimagelicenses/machine-typemaintenance-eventnamenetwork-interfaces/preemptedremaining-cpu-timescheduling/service-accounts/tagsvirtual-clock/zone[email  protected]:~#

你明白我的意思吗?
这对于报告和自动化可能非常方便。
如果还需要获取内部IP, 请使用以下命令。
curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/ip

【如何找到Google Cloud VM的外部IP()】你正在学习GCP管理吗?看看这个很棒的在线课程。

    推荐阅读