다음을 통해 공유


가상 네트워크 피어링 구성

적용 대상: Windows Server 2022, Windows Server 2019, Windows Server 2016, Azure Stack HCI, 버전 21H2 및 20H2

이 절차에서는 Windows PowerShell을 사용하여 각각 하나의 서브넷이 있는 두 개의 가상 네트워크를 만듭니다. 그런 다음 두 가상 네트워크 간의 피어링을 구성하여 두 가상 네트워크 간에 연결을 사용하도록 설정합니다.

Important

환경의 속성을 업데이트해야 합니다.

1단계: 첫 번째 가상 네트워크 만들기

이 단계에서는 Windows PowerShell을 사용하여 HNV 공급자 논리 네트워크를 찾아 하나의 서브넷으로 첫 번째 가상 네트워크를 만듭니다. 다음 예제 스크립트는 하나의 서브넷을 사용하여 Contoso의 가상 네트워크를 만듭니다.

#Find the HNV Provider Logical Network

$logicalnetworks = Get-NetworkControllerLogicalNetwork -ConnectionUri $uri
foreach ($ln in $logicalnetworks) {
   if ($ln.Properties.NetworkVirtualizationEnabled -eq "True") {
      $HNVProviderLogicalNetwork = $ln
   }
}

#Create the Virtual Subnet

$vsubnet = new-object Microsoft.Windows.NetworkController.VirtualSubnet
$vsubnet.ResourceId = "Contoso"
$vsubnet.Properties = new-object Microsoft.Windows.NetworkController.VirtualSubnetProperties
$vsubnet.Properties.AddressPrefix = "24.30.1.0/24"
$uri=”https://restserver”

#Create the Virtual Network

$vnetproperties = new-object Microsoft.Windows.NetworkController.VirtualNetworkProperties
$vnetproperties.AddressSpace = new-object Microsoft.Windows.NetworkController.AddressSpace
$vnetproperties.AddressSpace.AddressPrefixes = @("24.30.1.0/24")
$vnetproperties.LogicalNetwork = $HNVProviderLogicalNetwork
$vnetproperties.Subnets = @($vsubnet)
New-NetworkControllerVirtualNetwork -ResourceId "Contoso_VNet1" -ConnectionUri $uri -Properties $vnetproperties

2단계: 두 번째 가상 네트워크 만들기

이 단계에서는 하나의 서브넷을 사용하여 두 번째 가상 네트워크를 만듭니다. 다음 예제 스크립트는 하나의 서브넷으로 Woodgrove의 가상 네트워크를 만듭니다.


#Create the Virtual Subnet

$vsubnet = new-object Microsoft.Windows.NetworkController.VirtualSubnet
$vsubnet.ResourceId = "Woodgrove"
$vsubnet.Properties = new-object Microsoft.Windows.NetworkController.VirtualSubnetProperties
$vsubnet.Properties.AddressPrefix = "24.30.2.0/24"
$uri=”https://restserver”

#Create the Virtual Network

$vnetproperties = new-object Microsoft.Windows.NetworkController.VirtualNetworkProperties
$vnetproperties.AddressSpace = new-object Microsoft.Windows.NetworkController.AddressSpace
$vnetproperties.AddressSpace.AddressPrefixes = @("24.30.2.0/24")
$vnetproperties.LogicalNetwork = $HNVProviderLogicalNetwork
$vnetproperties.Subnets = @($vsubnet)
New-NetworkControllerVirtualNetwork -ResourceId "Woodgrove_VNet1" -ConnectionUri $uri -Properties $vnetproperties

3단계: 첫 번째 가상 네트워크에서 두 번째 가상 네트워크로의 피어링 구성

이 단계에서는 이전 두 단계에서 만든 첫 번째 가상 네트워크와 두 번째 가상 네트워크 간에 피어링을 구성합니다. 다음 예제 스크립트는 Contoso_vnet1 Woodgrove_vnet1가상 네트워크 피어링을 설정합니다.

$peeringProperties = New-Object Microsoft.Windows.NetworkController.VirtualNetworkPeeringProperties
$vnet2 = Get-NetworkControllerVirtualNetwork -ConnectionUri $uri -ResourceId "Woodgrove_VNet1"
$peeringProperties.remoteVirtualNetwork = $vnet2

#Indicate whether communication between the two virtual networks
$peeringProperties.allowVirtualnetworkAccess = $true

#Indicates whether forwarded traffic is allowed across the vnets
$peeringProperties.allowForwardedTraffic = $true

#Indicates whether the peer virtual network can access this virtual networks gateway
$peeringProperties.allowGatewayTransit = $false

#Indicates whether this virtual network uses peer virtual networks gateway
$peeringProperties.useRemoteGateways =$false

New-NetworkControllerVirtualNetworkPeering -ConnectionUri $uri -VirtualNetworkId “Contoso_vnet1” -ResourceId “ContosotoWoodgrove” -Properties $peeringProperties

Important

이 피어링을 만든 후 vnet 상태 시작됨을 표시합니다.

4단계: 두 번째 가상 네트워크에서 첫 번째 가상 네트워크로의 피어링 구성

이 단계에서는 위의 1단계와 2단계에서 만든 첫 번째 가상 네트워크와 두 번째 가상 네트워크 간에 피어링을 구성합니다. 다음 예제 스크립트는 Woodgrove_vnet1 Contoso_vnet1가상 네트워크 피어링을 설정합니다.

$peeringProperties = New-Object Microsoft.Windows.NetworkController.VirtualNetworkPeeringProperties
$vnet2=Get-NetworkControllerVirtualNetwork -ConnectionUri $uri -ResourceId "Contoso_VNet1"
$peeringProperties.remoteVirtualNetwork = $vnet2

# Indicates whether communication between the two virtual networks is allowed
$peeringProperties.allowVirtualnetworkAccess = $true

# Indicates whether forwarded traffic will be allowed across the vnets
$peeringProperties.allowForwardedTraffic = $true

# Indicates whether the peer virtual network can access this virtual network's gateway
$peeringProperties.allowGatewayTransit = $false

# Indicates whether this virtual network will use peer virtual network's gateway
$peeringProperties.useRemoteGateways =$false

New-NetworkControllerVirtualNetworkPeering -ConnectionUri $uri -VirtualNetworkId “Woodgrove_vnet1” -ResourceId “WoodgrovetoContoso” -Properties $peeringProperties

이 피어링을 만든 후 vnet 피어링 상태 두 피어 모두에 대해 커넥트 표시됩니다. 이제 한 가상 네트워크의 가상 머신이 피어된 가상 네트워크의 가상 머신과 통신할 수 있습니다.