Beginner · Connectivity · 13 of 15

Peer two VNets

Your tasks
  • Peer vnet-a and vnet-b both ways with VNet access allowed
  • Get vm-a reaching vm-b on 443
  • Test the connection from vm-a with nc

vnet-a (10.10.0.0/16) and vnet-b (10.20.0.0/16) are separate networks, so vm-a can't reach the HTTPS service on vm-b (10.20.1.4, port 443). Peer the two VNets, watch the peering state change, then test the connection from vm-a.

You'll learn
Virtual network peering
  1. Create the link from vnet-a to vnet-b.

    az network vnet peering create -g rg-lab --name a-to-b --vnet-name vnet-a --remote-vnet vnet-b --allow-vnet-access
    What's this?

    Connects two virtual networks, or changes what the connection allows. A peering needs a link from each side.

    • -g the resource group the resources live in
    • --name the name of the thing to look at or change
    • --vnet-name the virtual network
    • --remote-vnet the virtual network on the other side
    • --vnet-name vnet-a the local side of this link
    • --remote-vnet vnet-b the other VNet, by name or resource ID
    • --allow-vnet-access let traffic flow through this link
  2. Check the state from vnet-a. It should say Initiated.

    az network vnet peering list -g rg-lab --vnet-name vnet-a -o table
    What's this?

    Shows the peerings on a virtual network and their state.

    • -g the resource group the resources live in
    • --vnet-name the virtual network
  3. Create the reverse link.

    az network vnet peering create -g rg-lab --name b-to-a --vnet-name vnet-b --remote-vnet vnet-a --allow-vnet-access
    What's this?

    Connects two virtual networks, or changes what the connection allows. A peering needs a link from each side.

    • -g the resource group the resources live in
    • --name the name of the thing to look at or change
    • --vnet-name the virtual network
    • --remote-vnet the virtual network on the other side
  4. Check the state again. Both links should now say Connected.

    az network vnet peering list -g rg-lab --vnet-name vnet-a -o table
    What's this?

    Shows the peerings on a virtual network and their state.

    • -g the resource group the resources live in
    • --vnet-name the virtual network
  5. Connect to vm-a so the next command runs from there.

    ssh vm-a
    What's this?

    Opens a shell on vm-a, so the next commands run on that VM. In this lab it's a shortcut. In real Azure you'd connect through something like Azure Bastion, or SSH to an address you can reach.

  6. From vm-a, test vm-b's port 443. Then type exit.

    nc -zv 10.20.1.4 443
    What's this?

    netcat, a standard Linux tool. Tries to open a TCP connection and reports whether it worked.

    • -z only check whether the port answers. Send no data
    • -v print the result in words
    • 10.20.1.4 where to connect
    • 443 the port to try
Sources on Microsoft Learn (3)
0/2 changes
Network map
?
  • Resource group, the outer dashed frame
  • Virtual network, with its address space top right
  • Subnet, with range and usable IPs (5 reserved)
  • Network security group. A small shield on a VM's NIC means the NIC has one too
  • Route table on the subnet
  • NICVM Appliance Private endpoint
  • Peering Connected Initiated or access off
  • Goal working Goal broken, X marks where it stops
  • Private DNS zone, dotted lines go to linked VNets
  • Orange pulse: what your last command changed. Drag to pan, Ctrl and scroll to zoom.
Resource grouprg-labvnet-a: tap to inspectVirtual networkvnet-a10.10.0.0/16subnet-app: tap to inspectsubnet-app10.10.1.0/24 · 251 usablevm-a 10.10.1.4: tap to inspectNICvm-a10.10.1.4vnet-b: tap to inspectVirtual networkvnet-b10.20.0.0/16subnet-app: tap to inspectsubnet-app10.20.1.0/24 · 251 usablevm-b 10.20.1.4: tap to inspectNICvm-b10.20.1.4:443 ✗
  • vm-a → vm-b:443should work: dropped by routing
Goals 0/3
Cloud Shell · bashVMsrg-lab · eastus2
cloudshell:~$