0
0
Azurecloud~10 mins

VNet-to-VNet connectivity in Azure - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - VNet-to-VNet connectivity
Create VNet1
Create VNet2
Create VPN Gateway in VNet1
Create VPN Gateway in VNet2
Create Connection from VNet1 Gateway to VNet2 Gateway
Create Connection from VNet2 Gateway to VNet1 Gateway
Verify Connectivity
Traffic flows securely between VNets
This flow shows setting up two virtual networks, adding gateways, connecting them, and enabling secure traffic flow.
Execution Sample
Azure
az network vnet create --name VNet1 --resource-group RG --address-prefix 10.1.0.0/16
az network vnet create --name VNet2 --resource-group RG --address-prefix 10.2.0.0/16
az network public-ip create --name GW1IP --resource-group RG --allocation-method Dynamic
az network public-ip create --name GW2IP --resource-group RG --allocation-method Dynamic
az network vnet-gateway create --name GW1 --vnet VNet1 --public-ip-address GW1IP --resource-group RG --gateway-type Vpn --vpn-type RouteBased --sku VpnGw1
az network vnet-gateway create --name GW2 --vnet VNet2 --public-ip-address GW2IP --resource-group RG --gateway-type Vpn --vpn-type RouteBased --sku VpnGw1
az network vpn-connection create --name Conn1 --resource-group RG --vnet-gateway1 GW1 --vnet-gateway2 GW2 --shared-key abc123
az network vpn-connection create --name Conn2 --resource-group RG --vnet-gateway1 GW2 --vnet-gateway2 GW1 --shared-key abc123
Commands to create two VNets, public IPs, gateways, and VPN connections between them.
Process Table
StepActionResource Created/UpdatedState/Result
1Create VNet1VNet1 with 10.1.0.0/16VNet1 ready
2Create VNet2VNet2 with 10.2.0.0/16VNet2 ready
3Create Public IP GW1IPPublic IP GW1IPGW1IP ready
4Create Public IP GW2IPPublic IP GW2IPGW2IP ready
5Create VPN Gateway in VNet1GW1 with public IP GW1IPGW1 provisioning started
6Create VPN Gateway in VNet2GW2 with public IP GW2IPGW2 provisioning started
7Create VPN Connection from GW1 to GW2Conn1 with shared keyConn1 connecting
8Create VPN Connection from GW2 to GW1Conn2 with shared keyConn2 connecting
9Verify ConnectivityTest ping from VNet1 to VNet2Ping successful, connectivity established
💡 Connectivity established after both VPN connections are active and gateways are provisioned
Status Tracker
ResourceInitial StateAfter CreationAfter ConnectionFinal State
VNet1Not existCreated with 10.1.0.0/16Connected via GW1Ready and connected
VNet2Not existCreated with 10.2.0.0/16Connected via GW2Ready and connected
GW1Not existProvisioning startedConnected to GW2 via Conn1Provisioned and connected
GW2Not existProvisioning startedConnected to GW1 via Conn2Provisioned and connected
Conn1Not existCreatedConnectingConnected
Conn2Not existCreatedConnectingConnected
Key Moments - 3 Insights
Why do we need to create two VPN connections (Conn1 and Conn2) instead of just one?
Each VPN gateway requires a connection object to the other gateway. Conn1 connects GW1 to GW2, and Conn2 connects GW2 to GW1. Both are needed for bidirectional communication, as shown in steps 7 and 8 in the execution_table.
What happens if the shared key between the VPN connections does not match?
The VPN connections will fail to establish secure tunnels. This is because the shared key is used to authenticate the connection. The execution_table shows connection states as 'connecting' and then 'connected' only when keys match.
Why do we create VPN gateways after creating VNets?
VPN gateways must be attached to existing VNets to route traffic. Creating VNets first (steps 1 and 2) ensures gateways (steps 5 and 6) have networks to connect to, as reflected in the resource creation order.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the first VPN gateway start provisioning?
AStep 5
BStep 1
CStep 7
DStep 9
💡 Hint
Check the 'Action' and 'Resource Created/Updated' columns in execution_table rows
According to variable_tracker, what is the state of GW2 after connection creation?
ANot exist
BProvisioning started
CConnected to GW1 via Conn2
DReady and connected
💡 Hint
Look at the 'After Connection' column for GW2 in variable_tracker
If the shared key is incorrect, what would change in the execution_table?
ASteps 7 and 8 would show 'Connected'
BSteps 7 and 8 would show 'Failed to connect'
CSteps 5 and 6 would fail provisioning
DStep 9 would show 'Ping successful'
💡 Hint
Refer to the 'State/Result' column for connection steps in execution_table
Concept Snapshot
VNet-to-VNet connectivity in Azure:
- Create two VNets with distinct address spaces
- Deploy VPN gateways in each VNet
- Create VPN connections between gateways with matching shared keys
- Connections enable secure, bidirectional traffic
- Verify connectivity by testing communication between VNets
Full Transcript
This visual execution shows how to connect two Azure virtual networks (VNets) using VPN gateways. First, two VNets are created with different IP address ranges. Then, public IP addresses are created for the gateways. VPN gateways are deployed in each VNet using those public IPs. Next, two VPN connections are created: one from the first gateway to the second, and another from the second gateway back to the first. Both connections use the same shared key for authentication. After provisioning and connection setup, connectivity is verified by testing network traffic between the VNets. The variable tracker shows the state changes of VNets, gateways, and connections through each step. Key moments clarify why two connections are needed, the importance of matching shared keys, and the order of resource creation. The quiz tests understanding of provisioning steps, resource states, and failure scenarios.