Lab 2: Deploy a Virtual Machine, Open a Web Port, Control Access With NSG and Stop Billing

Microsoft Azure Fundamentals AZ 900 50 min min read Updated: Nov 17, 2026 Beginner
Lab 2: Deploy a Virtual Machine, Open a Web Port, Control Access With NSG and Stop Billing
Beginner Topic 2 of 3

Goal

Create a small Linux VM, run a web page on it, control network access, then stop billing and clean up.

Step 1: Create the Group and VM

bash az group create --name rg-lab2 --location centralindia az vm create \ --resource-group rg-lab2 \ --name vm-web \ --image Ubuntu2204 \ --size Standard_B1s \ --admin-username azureuser \ --generate-ssh-keys \ --public-ip-sku Standard

The output shows the public IP address. Copy it.

Size note If Standard_B1s is not available in your region or subscription, pick another small size with az vm list-sizes --location centralindia -o table.

Step 2: Install a Web Server

bash az vm run-command invoke \ --resource-group rg-lab2 \ --name vm-web \ --command-id RunShellScript \ --scripts "sudo apt-get update && sudo apt-get install -y nginx"

Step 3: Try the Site (It Should Fail)

Open http://PUBLIC_IP in a browser. It does not load because the NSG blocks port 80 by default.

Step 4: Open Port 80

bash az vm open-port --resource-group rg-lab2 --name vm-web --port 80 --priority 900

Refresh the page. You should see the nginx welcome page.

Step 5: Look at the NSG Rule

  1. In the portal open rg-lab2, then the Network security group
  2. Under Inbound security rules find the rule for port 80 with priority 900
  3. Notice the default DenyAllInbound rule at the bottom

Step 6: Stop the Billing

bash az vm deallocate --resource-group rg-lab2 --name vm-web az vm get-instance-view --resource-group rg-lab2 --name vm-web --query instanceView.statuses[1].displayStatus -o tsv

The status should say VM deallocated. Compute charges stop. Disk and IP may still cost a little.

Step 7: Clean Up

bash az group delete --name rg-lab2 --yes --no-wait
Real life Do not leave SSH or RDP open to the whole internet. Use Bastion, a VPN or limit the source IP.

Questions

  1. Why did the page fail before Step 4?
  2. What is the difference between stopping and deallocating?
  3. Which command removes everything at the end?

Conclusion

You deployed a VM, installed a web server, opened a port through the NSG, deallocated to stop compute billing and cleaned up.

Quick Summary: VM; nginx; fail test; open port; NSG view; deallocate; cleanup.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators