Tutorial: Set up Azure Virtual Networks

This tutorial guides you through the essential steps of creating and configuring an Azure Virtual Network (VNet) to provide a secure and isolated environment for your cloud resources.

Prerequisites

Step 1: Create a Virtual Network

Using the Azure Portal
  1. Sign in to the Azure portal.
  2. In the search bar at the top, type "Virtual networks" and select it from the results.
  3. Click + Create.
  4. On the Basics tab:
    • Subscription: Select your Azure subscription.
    • Resource group: Select an existing one or click Create new to create a new one (e.g., MyVNetResourceGroup).
    • Name: Enter a name for your virtual network (e.g., MyVNet).
    • Region: Select an Azure region for your virtual network.
  5. On the IP Addresses tab:
    • IPv4 address space: Define your VNet's address space (e.g., 10.0.0.0/16). This is the range of IP addresses available for resources within the VNet.
    • Subnets: Click Add subnet to create at least one subnet.
      • Subnet name: Enter a name (e.g., DefaultSubnet).
      • Subnet address range: Define a range within the VNet's address space (e.g., 10.0.1.0/24).
  6. Review the other tabs (Security, Tags) as needed. For this tutorial, defaults are fine.
  7. Click Review + create, then click Create.
Using Azure CLI

You can also create a VNet using the Azure CLI. Ensure you have the Azure CLI installed and are logged in.

az group create --name MyVNetResourceGroup --location eastus
az network vnet create \
  --resource-group MyVNetResourceGroup \
  --name MyVNet \
  --address-prefix 10.0.0.0/16 \
  --subnet-name DefaultSubnet \
  --subnet-prefix 10.0.1.0/24

Step 2: Add a Second Subnet

It's best practice to divide your network into multiple subnets for better organization and security.

Using the Azure Portal
  1. Navigate to your virtual network (MyVNet).
  2. Under Settings, click Subnets.
  3. Click + Subnet.
  4. Enter a Subnet name (e.g., AppSubnet).
  5. Enter a Subnet address range within your VNet's address space (e.g., 10.0.2.0/24).
  6. Click Save.

Step 3: Deploy a Virtual Machine to Your VNet

Now, let's deploy a VM to one of your subnets to test the network connectivity.

Using the Azure Portal
  1. In the Azure portal, search for "Virtual machines" and select it.
  2. Click + Create, then Virtual machine.
  3. On the Basics tab, fill in the required details (Subscription, Resource group, VM name, Region, Image, Administrator account).
  4. On the Networking tab:
    • Virtual network: Select MyVNet.
    • Subnet: Select DefaultSubnet.
    • Ensure Public IP is set to Create new or select an existing one.
    • Ensure Public inbound ports is set to Allow selected ports and select SSH (22) and RDP (3389).
  5. Configure other settings as needed and click Review + create, then Create.

Step 4: Verify Connectivity

Once the VM is deployed, you can verify that it has an IP address from your VNet's subnet and can communicate with other resources (if any) within the VNet.

  1. Navigate to the virtual machine you just created.
  2. Under Overview, note the Private IP address. It should be within the range of DefaultSubnet (e.g., 10.0.1.4).
  3. Connect to your VM using SSH or RDP using its public IP address.
  4. From within the VM, try to ping another resource in the same VNet (if you have one) or attempt to resolve DNS names for Azure services.

Next Steps

Congratulations! You have successfully set up a basic Azure Virtual Network and deployed a VM within it. Here are some next steps to explore:

Connect VNets with Peering Configure Network Security Groups Implement User-Defined Routes Set up Azure Firewall