Skip to content

Azure-Samples/network-dotnet-manage-network-peering

Repository files navigation

page_type languages products extensions
sample
csharp
azure
services platforms
virtual-network
dotnet

Manage network peering between two virtual networks

Azure Network sample for enabling and updating network peering between two virtual networks Summary ...

  • This sample creates two virtual networks in the same subscription and then peers them, modifying various options on the peering. Details ...
  1. Create two virtual networks, network "A" and network "B"...
  • network A with two subnets
  • network B with one subnet
  • the networks' address spaces must not overlap
  • the networks must be in the same region
  1. Peer the networks...
  • the peering will initially have default settings:
    • each network's IP address spaces will be accessible from the other network
    • no traffic forwarding will be enabled between the networks
    • no gateway transit between one network and the other will be enabled
  1. Update the peering...
  • disable IP address space between the networks
  • enable traffic forwarding from network A to network B
  1. Delete the peering
  • the removal of the peering takes place on both networks, as long as they are in the same subscription Notes:
  • Once a peering is created, it cannot be pointed at another remote network later.
  • The address spaces of the peered networks cannot be changed as long as the networks are peered.
  • Gateway transit scenarios as well as peering networks in different subscriptions are possible but beyond the scope of this sample.
  • Network peering in reality results in pairs of peering objects: one pointing from one network to the other, and the other peering object pointing the other way. For simplicity though, the SDK provides a unified way to manage the peering as a whole, in a single command flow, without the need to duplicate commands for both sides of the peering, while enforcing the required restrictions between the two peerings automatically, as this sample shows. But it is also possible to modify each peering separately, which becomes required when working with networks in different subscriptions.

Running this Sample

To run this sample:

Set the environment variable CLIENT_ID,CLIENT_SECRET,TENANT_ID,SUBSCRIPTION_ID with the full path for an auth file. See how to create an auth file.

git clone https://github.com/Azure-Samples/network-dotnet-manage-network-peering.git

cd network-dotnet-manage-network-peering

dotnet build

bin\Debug\net452\ManageNetworkPeeringInSameSubscription.exe

More information

Azure Management Libraries for C# Azure .Net Developer Center If you don't have a Microsoft Azure subscription you can get a FREE trial account here


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.