Azure Virtual Network libraries for .NET

Configurare noua (How To)

Situatie

The Azure Virtual Network service enables you to securely connect Azure resources to each other with virtual networks (VNets). A VNet is a representation of your own network in the cloud. You can also connect VNets to each other, enabling resources connected to either VNet to communicate with each other.

Solutie

Management library

Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio Package Manager

PowerShell

Install-Package Microsoft.Azure.Management.Network.Fluent

.NET Core CLI

bash
dotnet add package Microsoft.Azure.Management.Network.Fluent

Code Example

This example shows how you can create a virtual network.

C#

/*

Include these “using” directives…

using Microsoft.Azure.Management.Network.Fluent;

using Microsoft.Azure.Management.Network.Fluent.Models;

*/

using (NetworkManagementClient client = new NetworkManagementClient(credentials))

{

// Define VNet

VirtualNetworkInner vnet = new VirtualNetworkInner()

{

Location = “West US”,

AddressSpace = new AddressSpace()

{

Location = “West US”,

AddressSpace = new AddressSpace()

{

AddressPrefixes = new List<string>() { “0.0.0.0/16” }

},

DhcpOptions = new DhcpOptions()

{

DnsServers = new List<string>() { “1.1.1.1”, “1.1.2.4” }

},

Subnets = new List<Subnet>()

{

new Subnet()

{

Name = subnet1Name,

AddressPrefix = “1.0.1.0/24”,

},

new Subnet()

{

Name = subnet2Name,

AddressPrefix = “1.0.2.0/24”,

}

}

};

await client.VirtualNetworks.CreateOrUpdateAsync(resourceGroupName, vNetName, vnet);

}

 

Tip solutie

Permanent

Voteaza

(8 din 31 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?