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
- An active Azure subscription. If you don't have one, you can create a free account.
- Basic understanding of networking concepts.
Step 1: Create a Virtual Network
Using the Azure Portal
- Sign in to the Azure portal.
- In the search bar at the top, type "Virtual networks" and select it from the results.
- Click + Create.
- 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.
- 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
).
- Review the other tabs (Security, Tags) as needed. For this tutorial, defaults are fine.
- 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
- Navigate to your virtual network (
MyVNet
).
- Under Settings, click Subnets.
- Click + Subnet.
- Enter a Subnet name (e.g.,
AppSubnet
).
- Enter a Subnet address range within your VNet's address space (e.g.,
10.0.2.0/24
).
- 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
- In the Azure portal, search for "Virtual machines" and select it.
- Click + Create, then Virtual machine.
- On the Basics tab, fill in the required details (Subscription, Resource group, VM name, Region, Image, Administrator account).
- 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).
- 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.
- Navigate to the virtual machine you just created.
- Under Overview, note the Private IP address. It should be within the range of
DefaultSubnet
(e.g., 10.0.1.4
).
- Connect to your VM using SSH or RDP using its public IP address.
- 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.