SaveMyCert
Log in
5 of 5 free questions left today·for unlimited practice
Implement and manage virtual networking

Azure Virtual Networks, Subnets, Peering & User-Defined Routes

14 min readAZ-104 · Implement and manage virtual networkingUpdated

An Azure virtual network (VNet) is the private, isolated network you build in a region, and every VNet is carved into subnets from an address space you define with CIDR notation. To connect two VNets you use virtual network peering, which links them over the Microsoft backbone with low latency and no gateway. On the AZ-104 exam you must configure VNets and subnets, peer networks in the same region or globally across regions, assign public IP addresses, and override Azure's built-in routing with user-defined routes. This lesson walks you through each task the way an administrator performs it in the portal, and it flags the two facts examiners love: Azure reserves five addresses in every subnet, and peering is non-transitive, so linking A to B and B to C never connects A to C. You will also learn to force subnet traffic through a firewall appliance and to troubleshoot broken connectivity with Network Watcher.

What you’ll learn
  • Create a virtual network and segment it into subnets using CIDR address ranges
  • Configure regional and global virtual network peering and explain why peering is non-transitive
  • Assign Basic and Standard SKU public IP addresses with static or dynamic allocation
  • Build user-defined routes to force traffic through a network virtual appliance or firewall
  • Troubleshoot connectivity with Network Watcher tools such as IP flow verify and effective routes

Design the address space and carve out subnets

When you create a virtual network you first define its address space as one or more private CIDR blocks, such as 10.0.0.0/16. You then divide that space into subnets, and each subnet must be a subset of the VNet range and must not overlap with another subnet. Plan the address space so it does not overlap with your on-premises network or any VNet you intend to peer with, because overlapping ranges make peering impossible.

The classic exam fact is that Azure reserves five IP addresses in every subnet. In a 10.0.0.0/24 subnet, Azure takes the network address 10.0.0.0, the default gateway 10.0.0.1, two addresses (10.0.0.2 and 10.0.0.3) that map to Azure DNS, and the broadcast address 10.0.0.255. That leaves 251 usable host addresses out of 256, not 254. Always subtract five when you size a subnet for a fixed number of machines.

Some services need their own dedicated subnet, and the name matters: Azure Bastion needs a subnet literally named AzureBastionSubnet, and a VPN or ExpressRoute gateway needs a GatewaySubnet. You can add, resize, or delete subnets after creation as long as no resource is using the affected range.

Connect two VNets with virtual network peering

Virtual network peering joins two VNets so that resources in each can reach the other over private IP addresses, using the Microsoft backbone rather than the public internet. There is no gateway, no VPN tunnel, and no encryption overhead in the data path. Peering comes in two forms. Regional (local) peering connects two VNets in the same Azure region. Global peering connects VNets in different regions, letting a VNet in East US talk privately to one in West Europe.

Peering is not transitive. This is the single most tested peering fact. If you peer VNet A to hub VNet B, and separately peer VNet B to VNet C, traffic still does not flow between A and C. Each pair needs its own peering, or you must route through a network virtual appliance in the hub using user-defined routes. A hub-and-spoke topology relies on exactly this behaviour: spokes reach the hub but not each other unless you deliberately route them.

You configure peering from both sides — a peering link on VNet A and a matching link on VNet B — and the connection status only shows Connected when both links exist. The two address spaces must not overlap.

AspectRegional peeringGlobal peering
Region scopeSame regionDifferent regions
Traffic pathMicrosoft backboneMicrosoft backbone
Transitive?NoNo
Typical useHub-and-spoke in one regionCross-region private connectivity

Tune peering with gateway transit and forwarded traffic

Each peering link exposes options that change what traffic is allowed and how remote networks are reached. Understanding them separates a passing answer from a guess.

Allow virtual network access is on by default and simply lets the two peered VNets communicate. Allow forwarded traffic permits traffic that did not originate in the peered VNet — for example, traffic that a network virtual appliance forwards on behalf of another network. You enable this on the hub side when spokes send traffic through a firewall in the hub.

Allow gateway transit and Use remote gateways work as a pair for hub-and-spoke designs. If the hub VNet holds a VPN or ExpressRoute gateway, you set Allow gateway transit on the hub's peering and Use remote gateways on the spoke's peering. The spoke then uses the hub's gateway to reach on-premises networks instead of deploying its own gateway, which saves cost and centralises connectivity. Only one VNet in a peering can use the remote gateway, and the spoke must not already have its own gateway. Remember that these options are set per link, so you configure the transit side and the consuming side separately.

Configure public IP addresses

A public IP address is a separate Azure resource you associate with a VM's network interface, a load balancer, a VPN gateway, Bastion, or a NAT gateway to allow inbound or outbound internet connectivity. Two decisions define it: the SKU and the allocation method.

The SKU is either Basic or Standard. A Standard public IP is always statically allocated, is secure by default (closed to inbound traffic until a network security group rule allows it), and supports availability zones. A Basic public IP can be static or dynamic and is open by default. Microsoft is retiring Basic SKU public IPs, so choose Standard for new production workloads; Standard is also required by the Standard Load Balancer.

The allocation method is static or dynamic. A dynamic address is assigned when the resource starts and released when it stops or deallocates, so it can change. A static address is reserved immediately and stays fixed for the life of the resource, which you want for DNS records, firewall allowlists, or anything that must not change. Note the SKU constraint: Standard is static-only, so the choice of SKU can decide the allocation for you.

Override default routing with user-defined routes

Azure automatically creates system routes so that subnets can reach each other, the internet, and peered or on-premises networks without any configuration. You cannot delete system routes, but you can override them with a user-defined route (UDR) placed in a route table that you associate with a subnet.

A route specifies an address prefix (the destination) and a next hop type. The next hop types are Virtual appliance, Virtual network gateway, Virtual network, Internet, and None. When a packet's destination matches a route, Azure uses the most specific prefix; where a UDR and a system route are equally specific, the UDR wins. Choosing None drops the traffic entirely.

The signature use of a UDR — and the answer whenever a question says "force traffic through a firewall appliance" — is to set a route for 0.0.0.0/0 with next hop type Virtual appliance and the private IP of a firewall or NVA. That sends all outbound subnet traffic to the appliance for inspection before it leaves. For this to work you must also enable IP forwarding on the appliance's network interface, or Azure will drop the forwarded packets.

Scenario: route a subnet through a firewall appliance

Your security team requires that every packet leaving the App subnet be inspected by a third-party firewall virtual machine before it reaches the internet. The firewall VM lives in a Security subnet with the private IP 10.0.2.4. Here is how you satisfy the requirement as an administrator.

First, deploy the firewall VM and, on its network interface, turn on IP forwarding so it can accept packets not addressed to itself. Second, create a route table and add a UDR with address prefix 0.0.0.0/0, next hop type Virtual appliance, and next hop address 10.0.2.4. Third, associate the route table with the App subnet. From that moment, the App subnet's default route to the internet is overridden, and all outbound traffic is steered to the firewall for inspection.

If you also want the firewall to inspect traffic between the App subnet and a peered spoke, remember peering is non-transitive: add matching routes and enable Allow forwarded traffic on the relevant peering links. To confirm the design works, open Network Watcher and check Effective routes on the App VM's NIC — you should see your 0.0.0.0/0 route pointing at the appliance, superseding the system Internet route.

Troubleshoot network connectivity

When traffic will not flow, Network Watcher is the toolbox the exam expects you to reach for. It is a regional service, and its diagnostics answer the common "why is this blocked?" questions without guesswork.

IP flow verify tells you whether a specific 5-tuple (source and destination IP, ports, and protocol) is allowed or denied, and if denied, it names the exact security rule responsible — the fastest way to catch an NSG that is blocking traffic. Next hop shows where Azure will send a packet bound for a given destination, revealing whether a UDR is diverting traffic unexpectedly. Effective routes lists every route applied to a network interface after system routes, UDRs, and peering are combined, so you can confirm your custom route is winning. Effective security rules does the same for the combined NSG rules on a NIC.

Connection troubleshoot and Connection monitor actively test reachability between a source and a destination and report latency and the hop where a connection fails. A practical order of attack is: run IP flow verify to rule out NSGs, then check Next hop and Effective routes to rule out routing, then use Connection troubleshoot to test the end-to-end path.

Tip. Expect scenarios that hinge on peering being non-transitive: "VNet A is peered to B and B to C" does not connect A to C, so the answer is a direct peering or routing through the hub. Watch for the subnet-sizing trap where Azure reserves five addresses per subnet. When a question says "force traffic through a firewall appliance," the answer is a user-defined route with next hop type Virtual appliance plus IP forwarding on the appliance NIC. Questions about a fixed, unchanging public address point to a Standard (static) public IP.

Key takeaways
  • Azure reserves five IP addresses in every subnet (network, gateway, two for DNS, broadcast), so a /24 yields 251 usable hosts.
  • VNet peering connects two VNets over the Microsoft backbone; regional peering is same-region and global peering spans regions.
  • Peering is non-transitive: A-to-B plus B-to-C does not connect A to C — each pair needs its own peering.
  • Use Allow gateway transit on the hub and Use remote gateways on the spoke so spokes share the hub's VPN or ExpressRoute gateway.
  • Standard SKU public IPs are static-only and secure by default; Basic SKU is being retired, so prefer Standard.
  • A user-defined route with next hop type Virtual appliance forces traffic through a firewall or NVA; enable IP forwarding on the appliance NIC.
  • Network Watcher's IP flow verify, Next hop, and Effective routes diagnose NSG and routing problems quickly.

Frequently asked questions

Is Azure virtual network peering transitive?

No. Peering is non-transitive. If VNet A is peered to VNet B and VNet B is peered to VNet C, A and C still cannot communicate. You must create a direct peering between A and C, or route traffic through a network virtual appliance in the hub using user-defined routes. This is why hub-and-spoke topologies require explicit routing for spoke-to-spoke traffic.

How many usable IP addresses are in an Azure subnet?

Azure reserves five addresses in every subnet: the network address, the default gateway, two addresses mapped to Azure DNS, and the broadcast address. So a /24 subnet has 256 total addresses but only 251 usable ones, and a /29 has 8 total but only 3 usable. Always subtract five when sizing a subnet.

What is the difference between regional and global VNet peering?

Regional (local) peering connects two virtual networks in the same Azure region, while global peering connects virtual networks in different regions. Both use the Microsoft backbone for private, low-latency connectivity, and both are non-transitive. Global peering enables private cross-region communication without a VPN gateway or public internet exposure.

How do I force all subnet traffic through a firewall in Azure?

Create a route table with a user-defined route for the prefix 0.0.0.0/0, set the next hop type to Virtual appliance, and enter the firewall's private IP as the next hop address. Associate the route table with the subnet, and enable IP forwarding on the firewall's network interface. All outbound traffic from that subnet is then steered to the firewall for inspection.

When should I choose a Standard SKU public IP address?

Choose Standard for almost all new workloads. Standard public IPs are statically allocated, are secure by default (closed until an NSG rule allows traffic), support availability zones, and are required by the Standard Load Balancer. Microsoft is retiring the Basic SKU, so avoid it for new deployments even though Basic supports dynamic allocation.

Test yourself on this topic
Practice questions with full explanations.
Practice now

Sign up free to mark lessons complete, bookmark topics and track your exam readiness.