Azure Virtual Networks
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks and see fewer ads — read each lesson on a single page with Pro
Azure Virtual Networks: A Comprehensive Guide
Introduction: Why Virtual Networks Matter
In the realm of cloud computing, the ability to replicate a traditional data center environment is essential for migrating existing workloads and building secure, scalable applications. Azure Virtual Network (VNet) serves as the fundamental building block for your private network in Microsoft Azure. It enables Azure resources—such as virtual machines, databases, and application services—to communicate securely with each other, the internet, and your on-premises data centers.
Without a Virtual Network, your cloud resources would exist in a disconnected state, unable to talk to one another or maintain the level of isolation required for enterprise-grade security. Understanding how to architect, configure, and manage VNets is not just a technical requirement for cloud engineers; it is a critical skill for ensuring that your infrastructure remains performant, compliant, and protected against unauthorized access. By mastering VNets, you gain granular control over IP address allocation, network routing, and traffic filtering, which are the cornerstones of a well-architected cloud environment.
Understanding the Core Architecture of Azure VNets
An Azure Virtual Network is logically isolated from other virtual networks in the Azure cloud. When you create a VNet, you are defining a private IP address space using CIDR notation. This IP space is then divided into subnets, which allow you to organize your resources based on their function, security requirements, or geographical location.
The Anatomy of a VNet
To effectively manage a VNet, you must understand the primary components that constitute its structure:
- Address Space: This is the range of private IP addresses you assign to your VNet. Azure supports both IPv4 and IPv6, though IPv4 is the industry standard for the vast majority of internal networking. When choosing an address space, you must ensure it does not overlap with your on-premises network or other connected VNets.
- Subnets: Subnets are segments of your VNet's IP address range. They allow you to partition your network into smaller pieces, which simplifies management and improves security. For example, you might have a "Web" subnet for your public-facing servers and a "Database" subnet for your backend storage, each with different access rules.
- Network Interfaces (NICs): Every virtual machine or resource deployed into a VNet requires a network interface. The NIC allows the resource to communicate with other resources within the VNet and the internet, depending on your configuration.
- Routing Tables: Azure automatically creates system routes for your VNet, but you can create custom route tables to control how traffic flows between subnets, virtual networks, and the internet. This is particularly useful for forcing traffic through a firewall or a virtual appliance.
Callout: Virtual Network vs. Physical Network In a traditional on-premises environment, a network is defined by physical switches, routers, and cabling. In Azure, the "hardware" is abstracted away by the software-defined networking (SDN) stack. This means you can create, modify, and delete network segments in seconds through code or the portal, without ever needing to physically touch a rack or connect a patch cable.
Designing Your Network Topology
Before deploying resources, you must plan your network layout. Poor planning at this stage can lead to difficult-to-resolve IP address conflicts or inefficient traffic patterns.
Choosing IP Address Ranges
When selecting your CIDR block (e.g., 10.0.0.0/16), you should aim for a range that is large enough to accommodate your future growth but not so large that it wastes IP addresses. If you plan to connect your VNet to an on-premises network via a VPN or ExpressRoute, it is imperative that your VNet IP range does not overlap with your existing corporate network. Overlapping ranges will cause routing conflicts that prevent communication between your cloud and local environments.
Subnet Strategy
A common mistake is creating subnets that are too small. While it is tempting to create a /29 subnet to save space, this only provides a few usable IP addresses after accounting for Azure’s reserved addresses (the first four and the last one). Always reserve enough room for your expected instance count plus a buffer for scaling.
Tip: Azure Reserved IPs Azure reserves five IP addresses in every subnet: the network address, the default gateway, and three addresses used for internal Azure services (DNS, DHCP, etc.). For a /24 subnet (256 addresses), you only have 251 usable IPs. Keep this in mind when sizing your subnets for high-density deployments.
Secure Traffic Flow: Network Security Groups (NSGs)
Once your network structure is in place, you must secure it. The primary tool for this is the Network Security Group (NSG). An NSG contains a list of security rules that allow or deny network traffic based on source/destination IP address, port, and protocol.
How NSGs Function
NSGs can be associated with either a subnet or a specific network interface. When associated with a subnet, the rules apply to all resources within that subnet. When associated with a NIC, the rules apply only to that specific resource.
- Inbound Rules: Control traffic entering your resource from the internet or other networks.
- Outbound Rules: Control traffic leaving your resource to the internet or other networks.
- Priority: Each rule has a priority (lower numbers are processed first). Once a match is found, processing stops.
- Default Rules: Azure provides default rules that allow traffic within the VNet and from Azure Load Balancers, while denying all other inbound internet traffic.
Practical Example: Restricting Access
Suppose you have a web server in a public subnet. You want to allow HTTP (port 80) and HTTPS (port 443) traffic from the internet but deny all other inbound traffic. Your NSG rule would look like this:
- Priority 100: Allow Source: Any, Destination: WebServerIP, Port: 80, Protocol: TCP, Action: Allow.
- Priority 110: Allow Source: Any, Destination: WebServerIP, Port: 443, Protocol: TCP, Action: Allow.
- Priority 65500: Deny Source: Any, Destination: Any, Port: Any, Protocol: Any, Action: Deny.
Connecting Virtual Networks
As your infrastructure grows, you will likely need to connect multiple VNets together. Azure provides two primary methods for this: VNet Peering and VPN Gateways.
VNet Peering
VNet Peering allows you to connect two VNets in the same or different Azure regions. Once peered, the VNets appear as one for connectivity purposes. Traffic between the VNets remains on the Microsoft backbone network, providing high bandwidth and low latency.
- Local Peering: Connects VNets within the same Azure region.
- Global Peering: Connects VNets across different Azure regions.
VPN Gateways
A VPN Gateway is a specific type of virtual network gateway used to send encrypted traffic between an Azure VNet and an on-premises location over the public internet. This is a common requirement for "hybrid cloud" setups where sensitive data must remain on-premises while applications run in the cloud.
Callout: Peering vs. VPN Gateway Use VNet Peering when you need high-speed, low-latency connectivity between two Azure VNets. Use a VPN Gateway when you need to connect your Azure environment to an external location (like your corporate office) or when you require specific encryption protocols that are not handled by the default peering mechanism.
Implementing Infrastructure as Code (IaC)
Manually configuring VNets via the Azure Portal is fine for learning, but it is not recommended for production environments. Using Infrastructure as Code (IaC) ensures that your network configuration is version-controlled, repeatable, and documented.
Deploying a VNet with Azure CLI
The Azure CLI provides a straightforward way to define your network. Below is a script to create a resource group and a virtual network with a specific subnet.
# Create a resource group
az group create --name MyNetworkRG --location eastus
# Create a virtual network
az network vnet create \
--name MyVNet \
--resource-group MyNetworkRG \
--address-prefix 10.0.0.0/16 \
--subnet-name FrontEnd \
--subnet-prefix 10.0.1.0/24
Explanation:
az group create: Initializes the container for your resources.az network vnet create: Defines the virtual network address space (10.0.0.0/16) and initializes the first subnet (10.0.1.0/24).
Deploying with Bicep
Bicep is a domain-specific language for deploying Azure resources. It is much cleaner and more readable than JSON-based ARM templates.
resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' = {
name: 'MyBicepVNet'
location: 'eastus'
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'BackendSubnet'
properties: {
addressPrefix: '10.0.2.0/24'
}
}
]
}
}
Explanation:
- This Bicep file defines the VNet resource type, the name, and the property block containing the address prefix.
- The
subnetsarray allows you to define multiple subnets in a single deployment, ensuring the network is built in a consistent state.
Best Practices for Network Architecture
To ensure your network remains maintainable and secure, follow these industry-standard practices:
- Use Hub-and-Spoke Topology: Centralize shared services (like firewalls, DNS, and logging) in a "Hub" VNet and host your applications in "Spoke" VNets. This reduces complexity and centralizes management.
- Principle of Least Privilege: Always configure your NSGs to allow the minimum amount of traffic necessary for your application to function. Avoid "Allow All" rules at all costs.
- Use Azure Bastion: Instead of assigning public IP addresses to your virtual machines for management, use Azure Bastion. It provides secure, seamless RDP/SSH connectivity directly from the Azure portal over SSL, keeping your VMs off the public internet.
- Monitor with Network Watcher: Azure Network Watcher is a suite of tools that allows you to monitor, diagnose, and view metrics for your network. Use "Next Hop" to troubleshoot routing issues and "IP Flow Verify" to test if traffic is being blocked by an NSG.
- Standardize Naming Conventions: Use a clear naming convention (e.g.,
vnet-prod-eastus-001) to make it easy to identify resources, especially as your environment scales.
Common Pitfalls and Troubleshooting
Even experienced engineers run into issues. Here are the most frequent mistakes:
- IP Overlap: Attempting to connect two VNets with the same address space will result in a routing failure. Always map out your IP ranges in a spreadsheet before deploying your first VNet.
- Misconfigured NSGs: Often, a developer will add a new rule to an NSG but put it at a higher priority than an existing "deny" rule, or vice versa. Always check the "Effective Security Rules" on the NIC to see exactly what is being applied.
- Forgetting Service Endpoints: If your VM needs to talk to an Azure Storage account, it might try to go over the public internet. By enabling Service Endpoints on your subnet, traffic to Azure services stays within the Microsoft backbone, increasing security and performance.
- Ignoring User-Defined Routes (UDRs): When you introduce a network virtual appliance (like a firewall), you must create a UDR to tell the subnet to route traffic to the appliance rather than the internet. If you forget this step, your traffic will bypass the firewall entirely.
Warning: The Dangers of Public IPs Never assign a public IP address to a virtual machine unless it is absolutely necessary. For most application architectures, you should place a Load Balancer or Application Gateway in front of your resources. This allows the load balancer to handle the public traffic while your backend VMs remain safely hidden in a private subnet.
Advanced Networking Concepts
As you move beyond the basics, you will encounter scenarios requiring more sophisticated networking control.
Azure Firewall
While NSGs provide layer 3 and 4 filtering (IPs and ports), Azure Firewall provides layer 7 filtering. This means you can filter traffic based on fully qualified domain names (FQDNs). For example, you could allow your VMs to access microsoft.com but block access to all other websites, which is impossible with standard NSGs.
Private Link
Azure Private Link allows you to access Azure PaaS services (like Azure SQL or Azure Key Vault) via a private IP address in your own VNet. This effectively brings the service "inside" your network, removing the need to expose these services to the public internet. This is a game-changer for compliance and data security.
Comparison Table: Networking Services
| Service | Primary Use Case | OSI Layer |
|---|---|---|
| NSG | Basic traffic filtering (IP/Port) | Layer 3 & 4 |
| Azure Firewall | Advanced filtering (FQDNs/Intrusion Detection) | Layer 3-7 |
| VPN Gateway | Secure connection to on-premises | Layer 3 |
| VNet Peering | High-speed connection between VNets | Layer 2/3 |
| Private Link | Secure access to PaaS services | Layer 3 |
Step-by-Step: Creating a Secure Subnet Deployment
To put this into practice, let’s walk through the manual process of setting up a secure, multi-tier network.
- Create the VNet: In the Azure portal, select "Create a resource" and choose "Virtual Network." Assign it an address space of
10.0.0.0/16. - Define Subnets: Create two subnets:
Subnet-Web(10.0.1.0/24) andSubnet-DB(10.0.2.0/24). - Create NSGs: Create two NSGs:
NSG-WebandNSG-DB. - Configure Rules:
- In
NSG-Web, add an inbound rule to allow port 80 and 443 fromInternet. - In
NSG-DB, add an inbound rule to allow port 3306 (MySQL) or 1433 (SQL Server) only from theSubnet-WebIP range.
- In
- Associate NSGs: Go to the Subnet settings for
Subnet-Weband associateNSG-Web. Repeat for the DB subnet. - Verify: Attempt to ping or access the DB server from the internet. It should fail. Then, attempt to access it from a VM inside the
Subnet-Web. It should succeed.
Scaling Your Network
As your cloud footprint expands, you will eventually outgrow a single VNet. The "Hub-and-Spoke" model mentioned earlier becomes essential. In this architecture, the "Hub" VNet contains the VPN Gateway, Azure Firewall, and shared management resources. The "Spoke" VNets contain the application workloads.
By peering the spokes to the hub, all traffic from the spokes can be routed through the central firewall in the hub before reaching the internet or on-premises. This provides a unified point of control for security auditing and traffic inspection, which is much easier to manage than dozens of disparate, unlinked networks.
Managing DNS in Azure
Azure provides default DNS resolution for resources within a VNet. However, for complex enterprise environments, you often need custom DNS solutions.
- Azure Private DNS Zones: This allows you to manage and resolve domain names in a virtual network without adding a custom DNS solution. It is perfect for internal naming conventions like
db.internal.myapp.com. - Custom DNS Servers: If you have an existing Active Directory DNS server on-premises, you can configure your VNet to use those DNS servers instead of the Azure-provided ones. This ensures that your cloud resources can resolve on-premises hostnames seamlessly.
Network Performance Considerations
Networking in the cloud is not just about connectivity; it is about performance. When designing your architecture, consider the following:
- Accelerated Networking: By enabling Accelerated Networking on your virtual machines, you offload the network processing from the VM's CPU to the network card's hardware. This significantly reduces latency and jitter, which is critical for high-performance applications and databases.
- Proximity Placement Groups: If you have a cluster of VMs that need to communicate with extremely low latency, use Proximity Placement Groups. This forces the VMs to be placed in the same physical data center, minimizing the physical distance the signal must travel.
- Bandwidth Limits: Every VM size has a maximum network throughput limit. If your application is data-heavy, ensure you choose a VM SKU that supports the required bandwidth.
Troubleshooting with Network Watcher
If you encounter a networking issue, do not guess. Use the tools provided in the "Network Watcher" blade:
- IP Flow Verify: Checks if a packet is allowed or denied based on your NSG rules. It will tell you exactly which rule is causing the block.
- Connection Troubleshoot: Tests the path between a source and destination (e.g., VM to VM or VM to Internet). It checks NSGs, route tables, and firewalls along the entire path.
- Packet Capture: Allows you to capture the actual traffic passing through a NIC. This is the "nuclear option" for debugging complex application-level connectivity issues that standard logs cannot explain.
Summary: Key Takeaways
As we conclude this module on Azure Virtual Networks, remember these core principles that will define your success as an Azure architect:
- Foundation First: Always design your IP address space with growth and on-premises integration in mind. Avoid overlapping CIDR blocks at all costs.
- Segmentation is Security: Use subnets to group your resources by function. Never put your public web servers and your private database servers in the same subnet.
- Default Deny: Your security posture should always start with a "deny all" approach. Explicitly allow only the traffic that is required for your services to function.
- IaC is Non-Negotiable: Use Bicep, Terraform, or Azure CLI to manage your network. This prevents "configuration drift" and ensures that your network is reproducible.
- Leverage Modern Tools: Use Azure Bastion instead of public IPs, use Private Link for PaaS services, and use Network Watcher to troubleshoot before you try to manually rewrite your routing tables.
- Plan for Hybrid: Even if you are "all-in" on the cloud today, you may need a VPN or ExpressRoute connection tomorrow. Designing your network with connectivity in mind from day one will save you a massive migration effort later.
- Monitor Performance: Networking is a resource like any other. Use Accelerated Networking and monitor your throughput to ensure your infrastructure isn't a bottleneck for your application performance.
By following these guidelines, you will build a resilient, secure, and high-performing network foundation that can support even the most demanding enterprise workloads. The virtual network is the heartbeat of your Azure environment—treat it with the care and planning it deserves, and your applications will run with the stability and security they require.
Continue the course
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons