Azure Virtual Network Setup Guide | Generated by AI

Home 2025.10

Azure Virtual Network Configuration Overview

To set up your described architecture in Azure, we’ll use a single Virtual Network (VNet) for simplicity, with multiple subnets to separate public-facing resources (like your API and admin service) from internal ones (like the MQ/Redis VM). This allows secure internal communication via private IPs while controlling public access through Network Security Groups (NSGs). We’ll also configure SSH access restricted to your team’s IP ranges.

Key principles:

This assumes you’re using Azure Portal or CLI; I’ll provide high-level steps with CLI examples for reproducibility. Costs apply for VNets, VMs, and public IPs.

Step 1: Create the Virtual Network and Subnets

Create a VNet with two subnets:

Using Azure CLI (install via az login first):

# Create resource group
az group create --name myResourceGroup --location eastus

# Create VNet
az network vnet create \
  --resource-group myResourceGroup \
  --name myVNet \
  --address-prefixes 10.0.0.0/16 \
  --subnet-name PublicSubnet \
  --subnet-prefixes 10.0.1.0/24

# Add private subnet
az network vnet subnet create \
  --resource-group myResourceGroup \
  --vnet-name myVNet \
  --name PrivateSubnet \
  --address-prefixes 10.0.2.0/24

Step 2: Create VMs and Assign Networking

CLI examples:

# Backend API VM
az vm create \
  --resource-group myResourceGroup \
  --name backendVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --admin-password <strong-password> \
  --vnet-name myVNet \
  --subnet PublicSubnet \
  --public-ip-sku Standard

# Get public IP for API
API_PUBLIC_IP=$(az vm show -d -g myResourceGroup -n backendVM --query publicIps -o tsv)

# MQ/Redis VM (no public IP)
az vm create \
  --resource-group myResourceGroup \
  --name mqVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --admin-password <strong-password> \
  --vnet-name myVNet \
  --subnet PrivateSubnet

# Get private IP for internal comm
MQ_PRIVATE_IP=$(az vm show -g myResourceGroup -n mqVM --query privateIps -o tsv)

# Admin VM
az vm create \
  --resource-group myResourceGroup \
  --name adminVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --admin-password <strong-password> \
  --vnet-name myVNet \
  --subnet PublicSubnet \
  --public-ip-sku Standard

# Get public IP for admin
ADMIN_PUBLIC_IP=$(az vm show -d -g myResourceGroup -n adminVM --query publicIps -o tsv)

On the VMs:

Step 3: Configure Network Security Groups (NSGs)

NSGs act as firewalls. Associate one NSG per subnet (or per NIC for finer control). Create rules to allow:

CLI for NSGs:

# Create NSG for Public Subnet
az network nsg create \
  --resource-group myResourceGroup \
  --name publicNSG

# Rules for public NSG
az network nsg rule create \
  --resource-group myResourceGroup \
  --nsg-name publicNSG \
  --name AllowHTTPS \
  --priority 100 \
  --direction Inbound \
  --access Allow \
  --protocol Tcp \
  --source-address-prefixes '*' \
  --source-port-ranges '*' \
  --destination-address-prefixes '*' \
  --destination-port-ranges 443

az network nsg rule create \
  --resource-group myResourceGroup \
  --nsg-name publicNSG \
  --name AllowHTTPAdmin \
  --priority 101 \
  --direction Inbound \
  --access Allow \
  --protocol Tcp \
  --source-address-prefixes 'TEAM_IPS' \
  --source-port-ranges '*' \
  --destination-address-prefixes '*' \
  --destination-port-ranges 80

az network nsg rule create \
  --resource-group myResourceGroup \
  --nsg-name publicNSG \
  --name AllowSSH \
  --priority 102 \
  --direction Inbound \
  --access Allow \
  --protocol Tcp \
  --source-address-prefixes 'TEAM_IPS' \
  --source-port-ranges '*' \
  --destination-address-prefixes '*' \
  --destination-port-ranges 22

# Associate public NSG to PublicSubnet
az network vnet subnet update \
  --resource-group myResourceGroup \
  --vnet-name myVNet \
  --name PublicSubnet \
  --network-security-group publicNSG

# Create NSG for Private Subnet
az network nsg create \
  --resource-group myResourceGroup \
  --name privateNSG

# Allow internal traffic from backend to MQ
az network nsg rule create \
  --resource-group myResourceGroup \
  --nsg-name privateNSG \
  --name AllowFromBackend \
  --priority 100 \
  --direction Inbound \
  --access Allow \
  --protocol Tcp \
  --source-address-prefixes '10.0.1.0/24'  # PublicSubnet CIDR
  --source-port-ranges '*' \
  --destination-address-prefixes '*' \
  --destination-port-ranges 6379  # Redis port

# Allow SSH to private VM if needed (from team via bastion or VPN)
az network nsg rule create \
  --resource-group myResourceGroup \
  --nsg-name privateNSG \
  --name AllowSSHPrivate \
  --priority 101 \
  --direction Inbound \
  --access Allow \
  --protocol Tcp \
  --source-address-prefixes 'TEAM_IPS' \
  --source-port-ranges '*' \
  --destination-address-prefixes '*' \
  --destination-port-ranges 22

# Associate private NSG
az network vnet subnet update \
  --resource-group myResourceGroup \
  --vnet-name myVNet \
  --name PrivateSubnet \
  --network-security-group privateNSG

Step 4: SSH Access for Team

Step 5: Access the Services

Additional Best Practices

For full docs: Azure VNet Overview, NSG Rules. If you need Terraform/ARM templates or specifics (e.g., exact team IPs), provide more details!


Back

x-ai/grok-4-fast

Donate