gpt4 book ai didi

google-cloud-platform - 如何更改外部临时 ip

转载 作者:行者123 更新时间:2023-12-04 04:06:08 24 4
gpt4 key购买 nike

我在 Google Cloud 中有一个具有外部临时 IP 的虚拟机实例。 IP 应该在实例停止和启动时更改,但事实并非如此。如何手动更改临时 IP?

最佳答案

根据文档IP AddressesExternal IP addresses :

Ephemeral external IP addresses are available to VM instances and forwarding rules. Ephemeral external IP addresses remain attached to a VM instance only until the VM is stopped and restarted or the instance is terminated. If an instance is stopped, any ephemeral external IP addresses that are assigned to the instance are released back into the general Compute Engine pool and become available for use by other projects. When a stopped instance is started again, a new ephemeral external IP address is assigned to the instance.

作为一种可行的解决方法,您可以在每次要更改时保留一个外部 IP 地址。请查看我的以下步骤:

  1. create虚拟机实例:
$ gcloud compute instances create instance-1 --zone=us-central1-a --machine-type=n1-standard-1 --image=ubuntu-1804-bionic-v20200610 --image-project=ubuntu-os-cloud
Created [https://www.googleapis.com/compute/v1/projects/test-prj/zones/us-central1-a/instances/instance-1].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n1-standard-1 10.128.0.5 35.239.122.55 RUNNING
  1. reserve一个外部 IP 地址:
$ gcloud compute addresses create external-ip-upd-1 --region=us-central1
Created [https://www.googleapis.com/compute/v1/projects/test-prj/regions/us-central1/addresses/external-ip-upd-1
$ gcloud compute addresses list
NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
external-ip-upd-1 34.66.150.26 EXTERNAL us-central1 RESERVED
  1. unassign VM 实例的现有外部 IP:
$ gcloud compute instances describe instance-1 --zone=us-central1-a 
...
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: external-nat
natIP: 34.66.150.26
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
fingerprint: 4vzdAl27owk=
kind: compute#networkInterface
name: nic0
network: https://www.googleapis.com/compute/v1/projects/test-prj/global/networks/default
networkIP: 10.128.0.5
subnetwork: https://www.googleapis.com/compute/v1/projects/test-prj/regions/us-central1/subnetworks/default
...
$ gcloud compute instances delete-access-config instance-1 --access-config-name "external-nat" --zone=us-central1-a
Updated [https://www.googleapis.com/compute/v1/projects/test-prj/zones/us-central1-a/instances/instance-1].
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n1-standard-1 10.128.0.5 RUNNING
  1. assign新的外部 IP:
$ gcloud compute instances add-access-config instance-1 --access-config-name "external-nat-upd-1" --address 34.66.150.26 --zone=us-central1-a
Updated [https://www.googleapis.com/compute/v1/projects/test-prj/zones/us-central1-a/instances/instance-1].
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n1-standard-1 10.128.0.5 34.66.150.26 RUNNING
  1. 为下一个更改重复 2-4 和 release未使用的外部 IP:
$ gcloud compute addresses create external-ip-upd-2 --region=us-central1 
$ gcloud compute addresses list
NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
external-ip-upd-2 34.71.149.223 EXTERNAL us-central1 RESERVED
external-ip-upd-1 34.66.150.26 EXTERNAL us-central1 IN_USE
$ gcloud compute instances delete-access-config instance-1 --access-config-name "external-nat-upd-1" --zone=us-central1-a
$ gcloud compute instances add-access-config instance-1 --access-config-name "external-nat-upd-2" --address 34.71.149.223 --zone=us-central1-a
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n1-standard-1 10.128.0.5 34.71.149.223 RUNNING
$ gcloud compute addresses delete external-ip-new --region=us-central1

如果您发现新保留的 IP 在前一段时间被使用,您可以保留另一个 IP 地址以获取另一个 IP 地址,然后释放未使用的 IP。

更新 如果您认为自己发现了问题,可以提交 reportGoogle Public Issue Tracker或请求 feature以避免手动重新配置。

关于google-cloud-platform - 如何更改外部临时 ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62461812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com