Virtual Network Concepts
A virtual network (VNet) is a logical representation of a physical network that is implemented in software.
Virtual networks enable you to securely and reliably connect Azure resources to each other, to the internet,
and to your on-premises networks.
Key Components of a Virtual Network
-
Address Space: A private IP address range that you assign to your virtual network.
This is typically a CIDR block (e.g., 10.0.0.0/16).
-
Subnets: Divisions of the virtual network's address space. Each subnet is a range
within the virtual network's address space. Resources are deployed into subnets.
-
Network Interfaces (NICs): Virtual network interfaces that connect Azure resources,
such as virtual machines, to a virtual network. Each NIC is associated with a subnet.
-
Route Tables: Define how network traffic is directed within your virtual network.
By default, Azure provides system routes, but you can create custom route tables for more control.
-
Network Security Groups (NSGs): Act as a virtual firewall for your VNets to filter
network traffic by allowing or denying inbound and outbound traffic to resources.
-
Gateways: Used for connecting your virtual network to other networks, such as your
on-premises network (VPN Gateway) or other VNets (VNet-to-VNet connection).
Why Use Virtual Networks?
- Isolation and Security: VNets provide a private and isolated environment for your
Azure resources. NSGs allow granular control over traffic flow.
- Connectivity: Easily connect resources within the VNet, to the internet, and to
on-premises environments.
- Scalability: Design your network topology to accommodate growth and changing requirements.
- Hybrid Cloud: Seamlessly integrate your Azure resources with your existing on-premises
infrastructure using VPN or ExpressRoute.
Common Scenarios
- Deploying multi-tier applications in different subnets.
- Connecting on-premises servers to Azure virtual machines securely.
- Creating a hub-and-spoke network topology.
- Segmenting networks for compliance or security reasons.
Did you know? You can peer VNets together to allow resources in different virtual networks
to communicate with each other. This is a powerful way to create complex, interconnected cloud environments.
Example: Creating a Basic Virtual Network
Here's a conceptual example of how you might define a virtual network and a subnet using Azure CLI:
# Define variables
RESOURCE_GROUP="myResourceGroup"
LOCATION="eastus"
VNET_NAME="myVNet"
SUBNET_NAME="mySubnet"
ADDRESS_PREFIX="10.0.0.0/16"
SUBNET_PREFIX="10.0.0.0/24"
# Create a resource group if it doesn't exist
az group create --name $RESOURCE_GROUP --location $LOCATION
# Create the virtual network
az network vnet create \
--resource-group $RESOURCE_GROUP \
--name $VNET_NAME \
--address-prefix $ADDRESS_PREFIX
# Create a subnet within the virtual network
az network vnet subnet create \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_NAME \
--address-prefix $SUBNET_PREFIX
Further Reading