OnCallReadyStart learning

Azure Lesson 33.24 · Azure V: Compute, App Hosting & the AZ-104 exam · 25 min read

VNet peering, public IPs and troubleshooting connectivity

In plain words

A virtual network is a private street with its own house numbers. Peering builds a bridge between two streets so houses can visit each other directly. But bridges do not chain: if street A has a bridge to the hub and the hub has a bridge to street B, A still cannot walk to B.

Public IP addresses are the front doors that face the internet. Troubleshooting is walking the path in order: is there a bridge, is there a route, does the guard let you in, is anyone home?

VNet peering, public IPs and troubleshooting connectivity

Azure II built the network the platform runs on: VNets and subnets, NSGs, route tables, private endpoints, a hub and spokes. This lesson is the administrator's side of the same network, the parts AZ-104 asks about and on-call needs at 2 am: the lifecycle of a peering (states, sync, what a change of address space does to it), public IP addresses as resources of their own, and a repeatable way to answer "why can't A reach B?" with Network Watcher instead of guessing.

Need to know: a peering is two objects, one per VNet; with one side it is Initiated, with both Connected, after one side is deleted the other shows Disconnected (delete and recreate it). Peering is never transitive. When a peered VNet's address space changes, the peerings must be synced (az network vnet peering sync). Standard public IPs are static, secure by default (nothing gets in until an NSG allows it) and can be zonal or zone-redundant; Basic is retired. Troubleshooting order: is the route there (show-next-hop, effective routes), is it allowed (effective NSG rules, test-ip-flow), does anything answer (test-connectivity).

The lab network

Three VNets in rg-az5-net: a hub and two spokes, both spokes peered with the hub. vm-app (in vnet-app) must reach the PostgreSQL VM vm-db (in vnet-data) on port 5432.

$ az network vnet list -g rg-az5-net --query "[].{vnet:name, space:addressSpace.addressPrefixes[0]}" -o table
Vnet       Space
---------  ------------
vnet-hub   10.90.0.0/16
vnet-app   10.91.0.0/16
vnet-data  10.92.0.0/16
$ for v in vnet-hub vnet-app vnet-data; do az network vnet peering list -g rg-az5-net --vnet-name $v --query "[].{vnet:'$v', peering:name, state:peeringState, sync:peeringSyncLevel}" -o tsv; done
vnet-hub	hub-to-app	Connected	FullyInSync
vnet-hub	hub-to-data	Connected	FullyInSync
vnet-app	app-to-hub	Connected	FullyInSync
vnet-data	data-to-hub	Connected	FullyInSync
$ az vm list -d -g rg-az5-net --query "[].{name:name, privateIp:privateIps, power:powerState}" -o table
Name    PrivateIp  Power
------  ---------  ----------
vm-app  10.91.1.4  VM running
vm-db   10.92.1.4  VM running

Is there a route?

Start from the source VM and ask Azure where a packet to the destination goes:

$ az network watcher show-next-hop -g rg-az5-net --vm vm-app --source-ip 10.91.1.4 --dest-ip 10.92.1.4 -o table
NextHopIpAddress  NextHopType  RouteTableId
----------------  -----------  ------------
                  None         System Route
$ az network nic show-effective-route-table -g rg-az5-net -n vm-appVMNic -o table
Source   State   Address Prefix  Next Hop Type  Next Hop IP
-------  ------  --------------  -------------  -----------
Default  Active  10.91.0.0/16    VnetLocal
Default  Active  10.90.0.0/16    VNetPeering
Default  Active  0.0.0.0/0       Internet
Default  Active  10.0.0.0/8      None
Default  Active  172.16.0.0/12   None
Default  Active  192.168.0.0/16  None
Default  Active  100.64.0.0/10   None
Default  Active  157.59.0.0/16   None
Default  Active  127.0.0.0/8     None
Default  Active  104.147.0.0/16  None
Default  Active  104.146.0.0/17  None

None: the effective routes of vm-app's NIC have nothing for 10.92.0.0/16. They list the VNet itself, the hub (VNetPeering, 10.90.0.0/16), the internet and the default drops - but not vnet-data. That is non-transitive peering, made visible: vnet-app and vnet-data are both peered with the hub, and a peering only joins the two VNets it names. Two ways to fix it:

  • peer the spokes directly - cheap and simple when there are few spokes;
  • route spoke-to-spoke through an appliance in the hub (UDRs to a firewall, forwarded traffic allowed, gateway transit) - Azure II's hub-and-spoke incident, and what large networks do.

A peering, both sides

$ az network vnet peering create -g rg-az5-net --vnet-name vnet-app -n app-to-data --remote-vnet vnet-data --allow-vnet-access -o none
$ az network vnet peering show -g rg-az5-net --vnet-name vnet-app -n app-to-data --query peeringState -o tsv
Initiated
$ az network watcher show-next-hop -g rg-az5-net --vm vm-app --source-ip 10.91.1.4 --dest-ip 10.92.1.4 --query nextHopType -o tsv
None

Initiated - and still no route. Half a peering carries nothing; the other VNet's owner (often another team, another subscription) must create the matching side. With both:

$ az network vnet peering create -g rg-az5-net --vnet-name vnet-data -n data-to-app --remote-vnet vnet-app --allow-vnet-access -o none
$ az network vnet peering show -g rg-az5-net --vnet-name vnet-app -n app-to-data --query peeringState -o tsv
Connected
$ az network watcher show-next-hop -g rg-az5-net --vm vm-app --source-ip 10.91.1.4 --dest-ip 10.92.1.4 -o table
NextHopIpAddress  NextHopType  RouteTableId
----------------  -----------  ------------
                  VNetPeering  System Route

The flags on each side, and what they do:

flagon which sideeffect
--allow-vnet-accessboth (default true)the two address spaces can talk at all
--allow-forwarded-trafficthe side receiving traffic forwarded by an applianceaccept packets that did not originate in the remote VNet
--allow-gateway-transitthe hub (it has the VPN/ExpressRoute gateway)let the peer use this VNet's gateway
--use-remote-gatewaysthe spokesend on-premises traffic through the remote (hub) gateway; the spoke must have no gateway of its own

Peering works across regions (global VNet peering) and across subscriptions and tenants (with rights on both VNets); traffic stays on Microsoft's backbone and is billed per GB in each direction. Address spaces must not overlap, which is why IP plans are global, not per team.

When the address space changes

vnet-data needs a second range for a new subnet. VNets can grow while peered, but the peerings do not learn about it by themselves:

$ az network vnet update -g rg-az5-net -n vnet-data --address-prefixes 10.92.0.0/16 10.93.0.0/16 -o none
$ az network vnet peering list -g rg-az5-net --vnet-name vnet-app --query "[].{peering:name, state:peeringState, sync:peeringSyncLevel}" -o table
Peering      State      Sync
-----------  ---------  --------------
app-to-hub   Connected  FullyInSync
app-to-data  Connected  LocalNotInSync
$ az network vnet peering sync -g rg-az5-net --vnet-name vnet-app -n app-to-data -o none
$ az network vnet peering sync -g rg-az5-net --vnet-name vnet-hub -n hub-to-data -o none
$ az network vnet peering list -g rg-az5-net --vnet-name vnet-app --query "[].{peering:name, state:peeringState, sync:peeringSyncLevel}" -o table
Peering      State      Sync
-----------  ---------  -----------
app-to-hub   Connected  FullyInSync
app-to-data  Connected  FullyInSync

LocalNotInSync on every peering that points at vnet-data: those VNets still route only 10.92.0.0/16 to it. A sync on each of them fixes it (the portal shows "Sync" on the peering). Forget one, and the new subnet is reachable from some spokes and not others - a fun ticket.

Public IP addresses

A public IP is a resource of its own, attached to a NIC, a load balancer frontend, a NAT gateway, Bastion, an Application Gateway or a VPN gateway:

$ az network public-ip create -g rg-az5-net -n pip-basic --sku Basic
ERROR: (simulator) Basic SKU public IP addresses can no longer be created: creation stopped on 31 March 2025 and the SKU was retired on 30 September 2025. Use --sku Standard (static, secure by default: inbound traffic needs an NSG rule).
$ az network public-ip create -g rg-az5-net -n pip-app --sku Standard --allocation-method Dynamic
ERROR: (StandardSkuPublicIPAddressesMustBeStatic) Standard sku publicIp /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-net/providers/Microsoft.Network/publicIPAddresses/pip-app must have AllocationMethod set to Static.
Code: StandardSkuPublicIPAddressesMustBeStatic
Message: Standard sku publicIp /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-net/providers/Microsoft.Network/publicIPAddresses/pip-app must have AllocationMethod set to Static.
$ az network public-ip create -g rg-az5-net -n pip-app --sku Standard --zone 1 2 3 --dns-name app-az5 -o none
$ az network public-ip show -g rg-az5-net -n pip-app --query "{ip:ipAddress, allocation:publicIPAllocationMethod, sku:sku.name, tier:sku.tier, zones:join(',', zones), fqdn:dnsSettings.fqdn}" -o json
{
  "allocation": "Static",
  "fqdn": "app-az5.westeurope.cloudapp.azure.com",
  "ip": "20.103.68.112",
  "sku": "Standard",
  "tier": "Regional",
  "zones": "1,2,3"
}
  • SKU: Standard only - Basic public IPs could no longer be created after 31 March 2025 and were retired on 30 September 2025 (existing ones had to be upgraded).
  • Allocation: Standard is always static: the address is reserved until you delete the resource, even while the VM is deallocated.
  • Secure by default: nothing reaches a Standard IP until an NSG on the NIC or subnet allows it.
  • Zones: zone-redundant (--zone 1 2 3) survives a zone failure; zonal (--zone 2) lives in one. It cannot change after creation.
  • Tier: Regional (the default) or Global (for a cross-region load balancer); routing preference Microsoft network (default) or Internet (cheaper egress, enters Microsoft's network closer to Azure); a DNS label gives <label>.<region>.cloudapp.azure.com; a public IP prefix reserves a contiguous block (for a partner's allowlist).

Attaching it to the VM's NIC (the IP configuration made by az vm create is ipconfig<vm>):

$ az network nic ip-config list -g rg-az5-net --nic-name vm-appVMNic --query "[].name" -o tsv
ipconfigvm-app
$ az network nic ip-config update -g rg-az5-net --nic-name vm-appVMNic -n ipconfigvm-app --public-ip-address pip-app -o none
$ az network public-ip delete -g rg-az5-net -n pip-app
ERROR: (PublicIPAddressInUse) Public IP address /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-net/providers/Microsoft.Network/publicIPAddresses/pip-app can not be deleted since it is still allocated to resource /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-net/providers/Microsoft.Network/networkInterfaces/vm-appVMNic/ipConfigurations/ipconfigvm-app. In order to delete the public IP, disassociate/detach the Public IP address from the resource.  To learn how to do this, see aka.ms/deletepublicip.
Code: PublicIPAddressInUse
Message: Public IP address /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-net/providers/Microsoft.Network/publicIPAddresses/pip-app can not be deleted since it is still allocated to resource /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-az5-net/providers/Microsoft.Network/networkInterfaces/vm-appVMNic/ipConfigurations/ipconfigvm-app. In order to delete the public IP, disassociate/detach the Public IP address from the resource.  To learn how to do this, see aka.ms/deletepublicip.

An associated public IP cannot be deleted: dissociate first (--public-ip-address ""). And having a public IP is not being reachable - the NIC's NSG decides:

Troubleshooting connectivity, in order

When "A cannot reach B", walk the path the packet takes and ask Azure at each step - Network Watcher has a tool per question (the Network Watcher part of this chapter covers them all):

stepquestioncommand
1does the source know a route?az network watcher show-next-hop, az network nic show-effective-route-table
2is the path peered/connected?az network vnet peering list (Connected, FullyInSync)
3does an NSG drop it, outbound or inbound?az network watcher test-ip-flow, az network nic list-effective-nsg
4does anything answer at the end?az network watcher test-connectivity (or connection monitor, continuously)
5is the right name resolving?dig / nslookup from the VM (private DNS zones, Azure II)
$ az network watcher test-connectivity -g rg-az5-net --source-resource vm-app --dest-address 10.92.1.4 --dest-port 5432 --query "{status:connectionStatus, sent:probesSent, failed:probesFailed}" -o json
{
  "failed": 0,
  "sent": 30,
  "status": "Reachable"
}
$ az network watcher test-ip-flow -g rg-az5-net --vm vm-db --direction Inbound --protocol TCP --local 10.92.1.4:5432 --remote 10.91.1.4:50000 -o json
{
  "access": "Allow",
  "ruleName": "defaultSecurityRules/AllowVnetInBound"
}

Reachable now: route, peering, both NSGs and a listener. The VirtualNetwork service tag in the default AllowVnetInBound rule includes peered address spaces, which is why the database's NSG let vm-app in without a new rule - and why a peering can open more than you meant to. If a step fails, it tells you which layer to fix; if test-connectivity fails with every earlier step green, the problem is on the VM (service down, OS firewall, wrong port).

On the exam (AZ-104 4.1.2, 4.1.3, 4.1.5): "VNet A peered to B, B to C; A cannot reach C" = peering is not transitive (peer A-C, or route through an NVA/Virtual WAN); "peering shows Initiated" = create the other side; "Disconnected" = delete and recreate; "added an address space, peers cannot reach it" = sync the peerings; "IP must not change when the VM is deallocated" = static (any Standard IP); "which tool shows the next hop" = Network Watcher next hop.

In an interview: "Two VNets are peered but VMs can't talk. Where do you look?" - "Peering state on both sides - Connected and in sync - then the effective routes on the source NIC for the destination prefix, then effective NSG rules both ways or IP flow verify, then a connectivity check to see whether anything listens. Overlapping address spaces and a UDR sending the prefix to an appliance are the usual surprises."

Why it helps

Peering is how almost every Azure landing zone is built - a hub and its spokes - and its rules decide most connectivity questions on AZ-104: both sides must be created, address spaces must not overlap, it is not transitive, and a changed address space needs a sync.

Public IP SKUs and allocation matter too: Standard is static and closed by default. The troubleshooting order in this lesson works for every network problem in the chapter.

Commands in this lesson

az

FAQ

Why does a peering show Initiated?

A peering is two links, one created from each VNet. Initiated means only one side exists; create the other and both turn Connected. The two VNets' address spaces must not overlap, and they can be in different regions (global peering) or subscriptions.

What does LocalNotInSync mean?

One VNet's address space changed after the peering was made, and the peering still advertises the old prefixes. az network vnet peering sync (on the remote side's peering) updates it. Until then the new range is unreachable over the peering.

What do the peering options do?

Allow virtual network access (on by default) lets the VNets talk. Allow forwarded traffic accepts traffic that did not start in the peered VNet - needed when an NVA forwards it. Gateway transit and use remote gateways let a spoke use the hub's VPN or ExpressRoute gateway.

Basic or Standard public IP?

Standard: static, zone-redundant or zonal, secure by default (closed until an NSG allows traffic), required for Standard load balancers and Bastion. Basic public IPs are retired (since 30 September 2025) and should not be used for anything new.

In which order do I troubleshoot a connection?

Peering state on both sides, then the effective routes on the source NIC for the destination, then the NSG verdict both ways (IP flow verify), then whether anything listens on the destination port. The lesson walks through each with its command.

In an interview Mid

Two VNets are peered but VMs cannot talk. Where do you look?

Peering state on both sides - Connected and in sync - then the effective routes on the source NIC for the destination prefix, then effective NSG rules both ways or IP flow verify, then a connectivity check to see whether anything listens. Overlapping address spaces and a UDR sending the prefix to an appliance are the usual surprises.

Also asked: Why is VNet peering not transitive and how do you work around it? · What changes when you add an address range to a peered VNet? · What is the difference between a Basic and a Standard public IP?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.