- Navigate to Google Cloud Console.
- Log in with your credentials if you aren't already logged in.
- Once logged in, click on the Navigation Menu (three horizontal lines) in the top-left corner.
- From the drop-down, go to VPC network under the Networking section.
- Click on VPC networks.
- At the top of the VPC networks page, click the Create VPC network button.
- Name: Set the name to
mynetwork
. - Subnet creation mode: Click on Automatic.
- Auto mode creates subnets in each region automatically, similar to the default network.
-
In the Firewall rules section, check all available firewall rule options, such as:
- Allow ICMP
- Allow internal traffic
- Allow RDP (3389)
- Allow SSH (22)
These rules replicate the standard firewall rules that come with the default network.
-
You will also see two implied rules:
- deny-all-ingress: Blocks all incoming traffic.
- allow-all-egress: Allows all outgoing traffic.
These cannot be unchecked as they are system-generated but have lower priority compared to the custom allow rules.
- Review the configuration and click Create.
- Wait for
mynetwork
to be created.
- Once the network is created, you will be redirected to the VPC networks page.
- You will notice that subnets have been automatically created for each region.
- Click on the mynetwork name and record the IP address range for subnets in different regions. These details will be used when creating resources like VM instances.
- If the default network is ever deleted, you can recreate it by following the same process of creating an auto mode VPC network, as described above.
You can use the following script to create a VPC network and associated firewall rules using the gcloud
command-line tool:
gcloud compute networks create vpc-02 --project=velocity-406304 --description=example\ vpc\ for\ learning.\ created\ by\ sritam --subnet-mode=auto --mtu=1460 --bgp-routing-mode=regional --bgp-best-path-selection-mode=legacy
gcloud compute firewall-rules create vpc-02-allow-custom --project=velocity-406304 --network=projects/velocity-406304/global/networks/vpc-02 --description=Allows\ connection\ from\ any\ source\ to\ any\ instance\ on\ the\ network\ using\ custom\ protocols. --direction=INGRESS --priority=65534 --source-ranges=10.128.0.0/9 --action=ALLOW --rules=all
gcloud compute firewall-rules create vpc-02-allow-icmp --project=velocity-406304 --network=projects/velocity-406304/global/networks/vpc-02 --description=Allows\ ICMP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=icmp
gcloud compute firewall-rules create vpc-02-allow-rdp --project=velocity-406304 --network=projects/velocity-406304/global/networks/vpc-02 --description=Allows\ RDP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network\ using\ port\ 3389. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=tcp:3389
gcloud compute firewall-rules create vpc-02-allow-ssh --project=velocity-406304 --network=projects/velocity-406304/global/networks/vpc-02 --description=Allows\ TCP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network\ using\ port\ 22. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=tcp:22
This guide outlines the steps to create a Virtual Machine (VM) instance in Google Cloud Console using a pre-existing VPC network.
- A Google Cloud account.
- A created VPC network (e.g.,
vpc-02
) with appropriate firewall rules.
- Navigate to Google Cloud Console.
- Log in with your credentials if you aren't already logged in.
- Click on the Navigation Menu (three horizontal lines) in the top-left corner.
- Select Compute Engine from the drop-down.
- Click on VM instances.
- If prompted, click on Enable to activate the Compute Engine API. This may take a few minutes.
- Click on the Create instance button at the top of the VM instances page.
- Name: Enter a name for your VM instance (e.g.,
my-vm-instance
). - Region and Zone: Select the region and zone where you want to create the instance. Ensure it matches one of the regions where your VPC subnets are available.
- Machine configuration: Choose the machine type based on your needs (e.g.,
e2-medium
,n1-standard-1
, etc.).
- In the Networking section, click on the Network interface dropdown.
- Select the VPC network you created earlier (e.g.,
vpc-02
). - Subnet: Choose the appropriate subnet from the dropdown. This will be one of the subnets created in your VPC network.
- External IP: Choose whether you want to assign an external IP to the VM. If you need to access it from the internet, select Ephemeral or Static as per your requirements.
- In the Firewall section, check the boxes for:
- Allow HTTP traffic (if needed).
- Allow HTTPS traffic (if needed).
- Ensure your firewall rules allow the necessary traffic (e.g., SSH, RDP) for your VM to function as intended.
- You can configure other settings, such as Boot disk, Identity and API access, and Management, security, disks, networking, sole-tenancy as needed.
- After reviewing your settings, click the Create button at the bottom of the page.
- Wait for the VM instance to be provisioned. You will be redirected to the VM instances page where you can see your newly created VM.
- Once the VM is running, you can connect to it using SSH by clicking the SSH button next to your instance on the VM instances page.
- After SSHing into the VM, run the following command to check the public IP of the instance:
curl ifconfig.me
gcloud compute instances create instance-02 --project=velocity-406304 --zone=us-central1-f --machine-type=f1-micro --network-interface=network-tier=STANDARD,stack-type=IPV4_ONLY,subnet=vpc-02 --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=893106818560-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=instance-02,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20240830,mode=rw,size=10,type=pd-balanced --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --labels=goog-ec-src=vm_add-gcloud --reservation-affinity=any