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:
| flag | on which side | effect |
|---|---|---|
--allow-vnet-access | both (default true) | the two address spaces can talk at all |
--allow-forwarded-traffic | the side receiving traffic forwarded by an appliance | accept packets that did not originate in the remote VNet |
--allow-gateway-transit | the hub (it has the VPN/ExpressRoute gateway) | let the peer use this VNet's gateway |
--use-remote-gateways | the spoke | send 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):
| step | question | command |
|---|---|---|
| 1 | does the source know a route? | az network watcher show-next-hop, az network nic show-effective-route-table |
| 2 | is the path peered/connected? | az network vnet peering list (Connected, FullyInSync) |
| 3 | does an NSG drop it, outbound or inbound? | az network watcher test-ip-flow, az network nic list-effective-nsg |
| 4 | does anything answer at the end? | az network watcher test-connectivity (or connection monitor, continuously) |
| 5 | is 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."