EN | ZH
This script supports changing the external IP address of a virtual machine (VM) on Google Cloud without affecting the data of the original VM.
PS: There will be a short service interruption when changing the ip.
The gcloud command line tool needs to be installed.
Test:
gcloud -v
https://github.com/Cocean001/change_gcloud_vm_ip/blob/main/screenshots/1.1-gcloud.png?raw=true
Make sure you are already logged into your Google Cloud account via gcloud (and of course you need to have a Google Cloud account first).
A VM virtual machine can be created manually. It can also be created on the command line using gcloud. Here is a sample configuration for creating it from the command line:
- VM name: my-vm-name
- VM system: debian-10
- VM type: n1-standard-1
- Firewall rules: Allow all inbound traffic
# Create the virtual machine
gcloud compute instances create my-vm-name --image-family debian-10 --image-project debian-cloud --machine-type n1-standard-1
# Set up firewall rules
gcloud compute firewall-rules create my-vm-name-allow-all --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=all - - -source-ranges=0 - -source-ranges=0 - -source-ranges=0 - -source-ranges=0 - -source-ranges=0 -source-ranges=0.0.0.0/0 --target-tags=my-vm-name
curl -O https://raw.githubusercontent.com/Cocean001/change_gcloud_vm_ip/main/change_ip.sh && chmod +x change_ip.sh
Or:
wget https://raw.githubusercontent.com/Cocean001/change_gcloud_vm_ip/main/change_ip.sh && chmod +x change_ip.sh
- VM_NAME: the virtual machine name of the ip to be modified.
- STATIC_IP_NAME: temporary name of the new IP, can be any value.
- REGION: which region you want to assign the VM to. You can refer to list of optional regions
bash change_ip.sh
MIT
- This script is for learning and communication purposes only. Use it in a formal environment at your own risk.