Funzo
Funzo

Reputation: 1290

How to reuse static IP address on google cloud compute engine from command line

I have reserved a static ip address in google cloud. However I don't understand how I can provision a new instance using gcloud and specify to use this private ip. At the moment my command looks like:

gcloud compute instances create demo-instance-1 \
--image-family debian-9 \
--image-project debian-cloud \
--machine-type n1-standard-1 \
--scopes "userinfo-email,cloud-platform" \
--metadata-from-file startup-script=instance-startup.sh \
--zone europe-west2-b \
--tags http-server

Upvotes: 0

Views: 647

Answers (1)

John Hanley
John Hanley

Reputation: 81464

To assign a static external IP address, add the --address flag during instance creation and provide the static external IP address:

gcloud compute instances create [INSTANCE_NAME] --address [IP_ADDRESS]

The external IP address is defined at networkInterfaces/accessConfigs/natIP when listing details on a compute instance.

Use this command to modify an existing instance

gcloud compute instances add-access-config [INSTANCE_NAME] --access-config-name=external-nat --zone [ZONE_NAME] --address=[IP_ADDRESS]

Upvotes: 2

Related Questions