Azure Virtual Network Fundamentals: Address Spaces, Subnets, Routing, Public IPs, DNS and Service Endpoints
What Is a Virtual Network?
A virtual network (VNet) is your private network in Azure. Resources such as VMs, scale sets and private endpoints connect to subnets inside it. A VNet lives in one region and can span all its zones.
text
VNet vnet-app 10.20.0.0/16 (region: centralindia)
├─ Subnet web 10.20.1.0/24
├─ Subnet app 10.20.2.0/24
├─ Subnet data 10.20.3.0/24
├─ Subnet AzureBastionSubnet 10.20.250.0/26 (name is fixed)
└─ Subnet GatewaySubnet 10.20.255.0/27 (name is fixed, for VPN/ExpressRoute)
Plan Your IP Addresses
- Use private ranges:
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
- Do not overlap with on-premises or other VNets you may connect (peering and VPN need unique ranges)
- Azure reserves 5 addresses per subnet (first four and last one)
- Plan room to grow. You can add address spaces but resizing a used subnet is hard
- Some services need dedicated subnets (Bastion, Firewall, Gateway, App Gateway, delegated subnets for some PaaS)
bash
az network vnet create -g rg-net -n vnet-app --address-prefixes 10.20.0.0/16 --subnet-name web --subnet-prefixes 10.20.1.0/24
az network vnet subnet create -g rg-net --vnet-name vnet-app -n app --address-prefixes 10.20.2.0/24
az network vnet subnet create -g rg-net --vnet-name vnet-app -n data --address-prefixes 10.20.3.0/24
az network vnet subnet list -g rg-net --vnet-name vnet-app -o table
Routing
| Route type | Description |
| System routes | Automatic: traffic inside the VNet, to the internet, to peered VNets |
| User-defined routes (UDR) | Your route table sends traffic to a next hop, for example a firewall (virtual appliance) for inspection |
| BGP routes | Learned from VPN or ExpressRoute gateways |
- The most specific prefix wins (longest prefix match)
- A UDR with
0.0.0.0/0 to a firewall forces all outbound traffic through the firewall (forced tunneling or central egress)
bash
az network route-table create -g rg-net -n rt-spoke
az network route-table route create -g rg-net --route-table-name rt-spoke -n default-to-fw --address-prefix 0.0.0.0/0 \
--next-hop-type VirtualAppliance --next-hop-ip-address 10.0.1.4
az network vnet subnet update -g rg-net --vnet-name vnet-app -n app --route-table rt-spoke
IP Addresses
| Type | Notes |
| Private IP | From the subnet, dynamic or static |
| Public IP (Standard SKU) | Static, zone-redundant option, secure by default (closed unless an NSG allows). Basic SKU is being retired, so use Standard |
| Public IP prefix | A block of public addresses |
Outbound Internet Without Public IPs
- Newer VNets are moving to private subnets by default with no implicit outbound access. Plan explicit outbound
- NAT Gateway: attach to a subnet so all outbound traffic uses stable public IPs and scales well
- Or send outbound through Azure Firewall
bash
az network public-ip create -g rg-net -n pip-nat --sku Standard --allocation-method Static
az network nat gateway create -g rg-net -n nat-app --public-ip-addresses pip-nat --idle-timeout 10
az network vnet subnet update -g rg-net --vnet-name vnet-app -n app --nat-gateway nat-app
DNS
| Feature | Use |
| Azure-provided DNS | Automatic name resolution inside a VNet |
| Azure DNS public zones | Host your internet domain records |
| Azure Private DNS zones | Private names (corp.internal, privatelink.blob.core.windows.net) linked to VNets |
| Azure DNS Private Resolver | Forward queries between Azure and on-premises DNS |
Service Endpoints and Private Endpoints
| Service endpoint | Private endpoint |
| How | Subnet gets a direct route to a PaaS service over the Azure backbone. The service still has a public IP | A private IP in your subnet represents the service (Private Link) |
| Reach from on-premises | No | Yes |
| Best for | Simple, free restriction of storage or SQL to a subnet | Strong isolation and hybrid access (modern default) |
VNet Peering
Peering connects two VNets privately over the Microsoft backbone. It is not transitive and needs non-overlapping ranges. The next lessons cover hub-and-spoke designs.
Practice
- Design an IP plan for three VNets that can all connect later
- Create a VNet with web, app and data subnets
- Create a route table that sends 0.0.0.0/0 to a virtual appliance IP
- Attach a NAT gateway to a subnet
- Explain service endpoint vs private endpoint
Conclusion
A VNet is a regional private network with subnets. Plan non-overlapping address space, use route tables for custom paths, NAT Gateway for outbound, Private DNS for names and private endpoints for private access to PaaS.
Quick Summary: VNet; IP plan; routing; IPs; outbound; DNS; endpoints; peering.