- Install the gcloud command-line tool.
- Set a default region and zone.
$ gcloud projects list
>
PROJECT_ID NAME PROJECT_NUMBER
data-collector-01 data collector 01 xxxxxxxxxx
...
$ gcloud compute instances list
>
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
alexandria europe-west1-d n1-standard-2 10.240.x.x xx.xxx.xxx.xx TERMINATED
...
$ gcloud compute addresses list
>
NAME REGION ADDRESS STATUS
alexandria europe-west1 xx.xxx.xxx.xx IN_USE
$ gcloud compute instances describe [INSTANCE_NAME]
>
...
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: External NAT
natIP: 104.155.61.176
type: ONE_TO_ONE_NAT
...
If natIP
is present
- You have to dissociate this IP before assign a new IP (step 2.)
Else
- Your can assign an external IP (step 3.)
gcloud compute instances delete-access-config [INSTANCE_NAME] \
--access-config-name [ACCESS_CONFIG_NAME]
- [INSTANCE_NAME] is the name of the instance.
- [ACCESS_CONFIG_NAME] is the access config to delete.
# Example :
gcloud compute instances delete-access-config my-instance \
--access-config-name "External NAT"
gcloud compute instances add-access-config [INSTANCE_NAME] \
--access-config-name [ACCESS_CONFIG_NAME] --address [IP_ADDRESS]
- [INSTANCE_NAME] is the name of the instance.
- [ACCESS_CONFIG_NAME] is access config to delete.
- [IP_ADDRESS] is the reserved IP address to add
# Example :
gcloud compute instances add-access-config my-instance \
--access-config-name "External NAT" --address "104.155.61.176"
####for a random IP:
# Example :
gcloud compute instances add-access-config my-instance --zone=us-central1-a