Using Console
Using CLI
gcloud compute instances list --filter="networkInterfaces.networkIP:10.128.0.0/9"
This command will list all the instances that are using the default network in GCP.
gcloud compute networks create [NEW_NETWORK_NAME] --subnet-mode=auto
Replace [NEW_NETWORK_NAME] with a name of your choice for the new network.
gcloud compute instances move [INSTANCE_NAME] --zone=[ZONE] --destination-network=[NEW_NETWORK_NAME]
Replace [INSTANCE_NAME] with the name of the instance that you want to move, [ZONE] with the zone where the instance is located, and [NEW_NETWORK_NAME] with the name of the new network that you created in step 2.
gcloud compute instances describe [INSTANCE_NAME] --zone=[ZONE] | grep network
This command will display the network interface details for the instance. Verify that the network interface is now using the new network that you created in step 2.
Using Python
gcloud compute instances list --filter="networkInterfaces.networkIP:10.128.0.0/9"
This command will list all the instances that are using the default network interface and have an IP address in the range of 10.128.0.0/9.
gcloud compute networks create [NETWORK_NAME] --subnet-mode=auto
Replace [NETWORK_NAME] with the name you want to give to your new VPC network.
gcloud compute networks subnets create [SUBNET_NAME] --network=[NETWORK_NAME] --region=[REGION] --range=[CIDR_RANGE]
Replace [SUBNET_NAME] with the name you want to give to your new subnet, [NETWORK_NAME] with the name of the VPC network you created in step 2, [REGION] with the region where you want to create the subnet, and [CIDR_RANGE] with the IP address range you want to assign to the subnet.
gcloud compute instance-templates create [TEMPLATE_NAME] --network=[NETWORK_NAME] --subnet=[SUBNET_NAME]
Replace [TEMPLATE_NAME] with the name you want to give to your new instance template, [NETWORK_NAME] with the name of the VPC network you created in step 2, and [SUBNET_NAME] with the name of the subnet you created in step 3.
gcloud compute instances create [INSTANCE_NAME] --source-instance-template=[TEMPLATE_NAME]
Replace [INSTANCE_NAME] with the name you want to give to your new instance and [TEMPLATE_NAME] with the name of the instance template you created in step 4.
gcloud compute instances list --filter="networkInterfaces.networkIP:[CIDR_RANGE]"
Replace [CIDR_RANGE] with the IP address range you assigned to the subnet in step 3.