Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Virtual Networks (VNet) Tutorial

Introduction to Azure Virtual Networks (VNet)

Azure Virtual Networks (VNet) are the foundation of your private network in Azure. VNets enable many types of Azure resources, such as Azure Virtual Machines (VM), to communicate with each other, the internet, and on-premises networks. VNets provide isolation, segmentation, and communication within Azure.

Creating a Virtual Network

To create a Virtual Network in the Azure portal, follow these steps:

  1. Navigate to the Azure portal (https://portal.azure.com).
  2. In the left-hand navigation pane, click on "Create a resource".
  3. In the search box, type "Virtual Network" and select it from the list.
  4. Click "Create" to open the "Create virtual network" page.
  5. Fill in the required fields such as Name, Address space, Subscription, Resource group, Location, and Subnet name.
  6. Click "Review + create" and then "Create" to create the VNet.

Configuring Subnets

Subnets allow you to segment the virtual network into one or more sub-networks. This helps in organizing and securing resources.

Example: To create a subnet in the Azure portal:

  1. Navigate to the Virtual Network you created.
  2. In the left-hand menu, click on "Subnets".
  3. Click on "+ Subnet" to add a new subnet.
  4. Provide a Subnet name and Address range.
  5. Click "OK" to create the subnet.

Connecting VNets with VNet Peering

VNet Peering enables you to seamlessly connect two Azure virtual networks. The virtual networks appear as one for connectivity purposes.

Example: To peer two VNets:

  1. Navigate to one of the Virtual Networks you want to peer.
  2. In the left-hand menu, select "Peerings" and then click "+ Add".
  3. Fill in the required fields like Name, Peer details, and Connection settings.
  4. Click "Add" to create the peering connection.

Network Security Groups (NSGs)

NSGs allow you to control inbound and outbound traffic to network interfaces, VMs, and subnets. They contain security rules that allow or deny network traffic based on source and destination IP address, port, and protocol.

Example: To create an NSG and associate it with a subnet:

  1. Navigate to the Azure portal and select "Create a resource".
  2. Search for "Network Security Group" and click "Create".
  3. Fill in the required fields like Name, Subscription, Resource group, and Location.
  4. Click "Create".
  5. Once created, navigate to the NSG and select "Inbound security rules" or "Outbound security rules" to add rules.
  6. Navigate to your Virtual Network, select the subnet, and associate the NSG with the subnet.

Example: Creating a VNet using Azure CLI

You can also create and manage VNets using Azure CLI. Below is an example of how to create a VNet and a subnet using Azure CLI.

az network vnet create --name MyVNet --resource-group MyResourceGroup --address-prefix 10.0.0.0/16 --subnet-name MySubnet --subnet-prefix 10.0.0.0/24
{ "newVNet": { "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "dhcpOptions": { "dnsServers": [] }, "id": "/subscriptions/{subscription-id}/resourceGroups/MyResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVNet", "location": "eastus", "name": "MyVNet", "resourceGroup": "MyResourceGroup", "subnets": [ { "addressPrefix": "10.0.0.0/24", "name": "MySubnet", "networkSecurityGroup": null, "provisioningState": "Succeeded", "resourceGroup": "MyResourceGroup" } ], "type": "Microsoft.Network/virtualNetworks" } }

Conclusion

In this tutorial, we covered the basics of Azure Virtual Networks (VNet), including how to create a VNet, configure subnets, connect VNets using VNet Peering, and apply Network Security Groups (NSGs). We also provided an example of creating a VNet using Azure CLI. Understanding and utilizing VNets is crucial for managing and securing your resources in Azure.