Overview and What You Will Learn
Azure Bastion is a managed service that gives you SSH and RDP access to VMs through the Azure Portal over HTTPS, so the VMs need no public IP address and no open management port. In this lab, you will deploy Bastion into a VNet, create a VM with no public IP and no inbound rules, connect to it from the browser, and confirm its management port was never exposed to the internet.
Why This Matters in Production
Bastion removes the temptation to expose a management port, because secure access is already available. A team at a company like Atlassian opens SSH to the internet on a production VM "just for now, I'll close it later," and that port becomes exactly where a real compromise starts. Automated scanners find open management ports within hours, not weeks.
Core Principles
Azure Bastion is deployed once per VNet and reaches VMs over their private IP addresses, so the VM's own port 22 or 3389 is never published. Your browser talks to Bastion over HTTPS on port 443, and Bastion talks to the VM privately inside Azure.
AzureBastionSubnet] V[VM, private IP only
subnet-vms] B -->|Private SSH| V end classDef person fill:#8B5CF6,color:#FFFFFF classDef service fill:#326CE5,color:#FFFFFF classDef vm fill:#10B981,color:#FFFFFF class U person class B service class V vm
Bastion requires its own dedicated subnet named exactly AzureBastionSubnet, with a /26 range or larger, inside the same VNet as the VMs it serves.
| Option | Management port exposed? | Best for |
|---|---|---|
| VM public IP with open port | Yes | Nothing in production |
| Azure Bastion | No | Browser access to many VMs |
| VPN or ExpressRoute | No | Private access to the whole network |
RememberBastion bills by the hour for as long as it exists, not per connection. Delete it when you finish the lab.
Detailed Step-by-Step Practical Lab
How to Create the Resource Group and VNet
export RG="rg-bastion-lab-mumbai" az group create --name $RG --location centralindia az network vnet create \ --resource-group $RG \ --name vnet-bastion-lab \ --address-prefix 10.0.0.0/16 \ --subnet-name subnet-vms \ --subnet-prefix 10.0.1.0/24How to Add the Required AzureBastionSubnet
The subnet name must be exactly AzureBastionSubnet, because Azure looks for that name when it deploys Bastion. A differently named subnet with the same range will not work.
az network vnet subnet create \ --resource-group $RG \ --vnet-name vnet-bastion-lab \ --name AzureBastionSubnet \ --address-prefix 10.0.2.0/26How to Create a Public IP for Bastion
This is the only public IP in the whole setup, and it belongs to Bastion, not to any VM. Bastion requires a Standard SKU public IP.
az network public-ip create \ --resource-group $RG \ --name pip-bastion-lab \ --sku StandardHow to Deploy Azure Bastion with the CLI
The Basic SKU is enough for browser-based SSH and RDP. Deployment typically takes 5 to 10 minutes.
az network bastion create \ --resource-group $RG \ --name bastion-lab \ --public-ip-address pip-bastion-lab \ --vnet-name vnet-bastion-lab \ --location centralindia \ --sku BasicHow to Create a VM With No Public IP and No Inbound Rules
Create an NSG with no custom rules first. The default AllowVnetInBound rule is enough for Bastion to reach the VM from inside the VNet, so you never add an allow rule for the internet. Read the password at the prompt so it does not land in your shell history.
az network nsg create --resource-group $RG --name nsg-vms read -s -p "Choose a VM admin password (12+ characters): " VM_PASS; echo az vm create \ --resource-group $RG \ --name vm-private-lab \ --image Ubuntu2204 \ --size Standard_B1s \ --vnet-name vnet-bastion-lab \ --subnet subnet-vms \ --public-ip-address "" \ --nsg nsg-vms \ --nsg-rule NONE \ --authentication-type password \ --admin-username azureadmin \ --admin-password "$VM_PASS"How to Confirm the VM Has No Public IP
Check the public IP and the NSG rules. Both should come back empty.
az vm show \ --resource-group $RG \ --name vm-private-lab \ --show-details \ --query "publicIps" --output tsv # Expected: empty output, no custom inbound rulesaz network nsg show \ --resource-group $RG \ --name nsg-vms \ --query "securityRules[].name" --output tsvHow to Connect to the VM Through Bastion
In the Azure Portal, open the VM, select Connect, then Connect via Bastion. Choose Password as the authentication type, enter azureadmin and the password you set, and select Connect. A browser SSH session opens. Inside it, check that the VM only has a private address:
hostname -I# Expected: a private address such as 10.0.1.4TipYou need Reader on the VM, its NIC, and the Bastion resource, plus a valid login on the VM, to connect. Bastion does not bypass RBAC.
How to Clean Up
Delete the resource group to stop Bastion's hourly billing.
az group delete --name $RG --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakeSkipping Bastion "just for a quick one-time fix" and temporarily opening RDP or SSH to the internet instead. The moment that thought appears is the moment to deploy Bastion, because "just for now" is where real compromises begin.
SecurityIf you attach an NSG to
AzureBastionSubnet, it must include the rules Bastion needs, such as inbound 443 from the internet and from the GatewayManager service tag, and outbound 22 and 3389 to the VNet. A missing rule breaks deployment or connections.
TipOne Bastion deployment serves every VM in its VNet, and can also reach VMs in peered VNets. It is a shared entry point, not a per-VM cost. For low-cost dev and test, the Developer SKU in supported regions connects to one VM at a time without a dedicated subnet.
- Keep the
AzureBastionSubnetname exact. Azure specifically looks for this name, and a different name will not work even with an identical range. - Use a /26 or larger for the Bastion subnet. Smaller ranges are rejected, and a larger one leaves room for scale units.
- Bastion complements, not replaces, access controls. RBAC and NSG rules on the destination VM's subnet still apply, because Bastion replaces the public IP and open port, not the need for permissions.
- Prefer SSH keys over passwords in real environments. Store keys in Azure Key Vault and select them in the Bastion connect pane instead of typing a password.
- Delete lab Bastion hosts promptly. The hourly charge continues whether or not anyone is connected.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az network vnet subnet create --name AzureBastionSubnet |
Create the required dedicated subnet |
az network bastion create --sku Basic |
Deploy Azure Bastion into a VNet |
az vm create --public-ip-address "" |
Create a VM with no public IP at all |
az vm show --show-details --query "publicIps" |
Confirm a VM has no public IP assigned |
az network nsg show --query "securityRules[].name" |
Confirm no custom inbound rules exist |
az network bastion list --output table |
Check that Bastion shows Succeeded provisioning |