Creating a Virtual Network in Azure - VNet Basics
What is an Azure Virtual Network (VNet)?
An Azure Virtual Network (VNet) is a fundamental building block in Microsoft Azure. It allows you to create private, isolated, and securely connected network environments within the Azure cloud. VNets enable you to host Azure resources, such as virtual machines, securely and connect them to your on-premises networks.
Key Concepts and Features
Azure VNets come with several important concepts and features:
- Address Space: VNets have an IP address range specified in CIDR notation, and you can further divide it into subnets.
- Subnets: You can create multiple subnets within a VNet, each with its own IP address range.
- Peering: VNets can be peered to allow communication between resources in different VNets.
- Virtual Network Gateway: You can create a VPN gateway for secure connections to on-premises networks or other VNets.
- Network Security Groups (NSGs): NSGs are used to control inbound and outbound traffic to network interfaces, VMs, and subnets.
Creating a Virtual Network
To create a VNet in Azure, follow these steps:
- Sign in to your Azure Portal.
- Navigate to the "Create a resource" section and search for "Virtual Network."
- Provide the necessary details such as the name, address space, and subnet details.
- Configure optional settings, like DNS servers, VPN gateway, and NSGs.
- Review and create the VNet.
Sample Code
Here's a simple example of how to create a Virtual Network in Azure using Azure PowerShell:
# Define variables
$rgName = "MyResourceGroup"
$location = "East US"
$vnetName = "MyVirtualNetwork"
$addressPrefix = "10.0.0.0/16"
$subnetName = "MySubnet"
$subnetPrefix = "10.0.0.0/24"
# Create a new resource group
New-AzResourceGroup -Name $rgName -Location $location
# Create a new Virtual Network with a subnet
$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $subnetPrefix
New-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName -Location $location -AddressPrefix $addressPrefix -Subnet $subnetConfig
Conclusion
Azure Virtual Networks are a fundamental component for building and managing Azure resources. They provide isolation, security, and connectivity for your cloud services and are essential for creating complex, multi-tiered applications in Azure.