23 ‐ Peering ‐ 3 vnet - SanjeevOCI/Azure GitHub Wiki
Configure VNet Peering in Azure for Hub-and-Spoke Architecture
In this setup, we will create 3 VNets: one Hub VNet and two Spoke VNets. The Hub VNet will act as the central point for communication, and the Spoke VNets will communicate with each other only through the Hub VNet.
1. Create the VNets
- Hub VNet:
We will use Terraform to create the 3 VNets as follows
- Hub VNet - HubVNet (10.0.0.0/24)
- Spoke VNet1 - SpokeVNet1 (10.0.0.0/27)
- Spoke VNet2 - SpokeVNet2 (10.0.0.32/27).
2. Configure VNet Peering
Step 1: Peer Hub VNet with Spoke VNet 1
- Go to HubVNet in the Azure Portal.
- Navigate to Peerings under the Settings section and click + Add.
- Configure the peering:
- Name:
HubToSpoke1
- Peering Link Name (Hub to Spoke):
HubToSpoke1
- Peering Link Name (Spoke to Hub):
Spoke1ToHub
- Virtual Network: Select
SpokeVNet1
. - Enable Allow forwarded traffic and Allow gateway transit.
- Disable Allow virtual network access for Spoke-to-Spoke communication.
- Name:
- Click OK to create the peering.
Step 2: Peer Hub VNet with Spoke VNet 2
- Go to HubVNet and navigate to Peerings.
- Click + Add and configure the peering:
- Name:
HubToSpoke2
- Peering Link Name (Hub to Spoke):
HubToSpoke2
- Peering Link Name (Spoke to Hub):
Spoke2ToHub
- Virtual Network: Select
SpokeVNet2
. - Enable Allow forwarded traffic and Allow gateway transit.
- Disable Allow virtual network access for Spoke-to-Spoke communication.
- Name:
- Click OK to create the peering.
Step 3: Disable Direct Peering Between Spoke VNets
- Do not create a direct peering between
SpokeVNet1
andSpokeVNet2
. This ensures that all communication between the spokes is routed through the Hub VNet.
3. Configure Route Tables
Step 1: Create a Route Table for Spoke VNets
- Navigate to Route Tables in the Azure Portal and click + Create.
- Configure the route table:
- Name:
SpokeRouteTable
- Region: Same as the VNets.
- Name:
- Add a route to the route table:
- Route Name:
DefaultRoute
- Address Prefix:
0.0.0.0/0
(or the address space of the other spoke VNet if specific routing is required). - Next Hop Type: Virtual Network Gateway (if using a gateway) or Virtual Appliance (if using a firewall in the Hub VNet).
- Route Name:
- Associate the route table with the subnets in
SpokeVNet1
andSpokeVNet2
.
Step 2: Configure the Hub VNet
- If using a firewall or NVA (Network Virtual Appliance) in the Hub VNet, ensure that it is configured to forward traffic between the spokes.
4. Test the Connectivity
- Deploy a VM in each VNet:
- One VM in
HubVNet
. - One VM in
SpokeVNet1
. - One VM in
SpokeVNet2
.
- One VM in
- Test connectivity:
- From the VM in
SpokeVNet1
, try to ping the VM inSpokeVNet2
. The traffic should route through theHubVNet
. - Verify that direct communication between
SpokeVNet1
andSpokeVNet2
is not possible without going through the hub.
- From the VM in
Diagram: Hub-and-Spoke Architecture with VNet Peering
+-------------------+
| Hub VNet |
| Address: 10.0.0.0/16 |
+-------------------+
|
+---------------+---------------+
| |
+-------------------+ +-------------------+
| Spoke VNet 1 | | Spoke VNet 2 |
| Address: 10.1.0.0/16 | | Address: 10.2.0.0/16 |
+-------------------+ +-------------------+
Key Points
- Hub VNet acts as the central point for all communication.
- Spoke VNets communicate with each other only through the Hub VNet.
- Route Tables ensure that traffic between spokes is routed through the Hub.
- No direct peering is created between the spokes to enforce the Hub-and-Spoke model.
This setup ensures centralized control, scalability, and secure communication between VNets in Azure.