本文可協助您使用 Virtual WAN 透過 ExpressRoute 線路連線到 Azure 中的資源。 如需虛擬 WAN 中 ExpressRoute 的詳細資訊,請參閱 關於虛擬 WAN 中的 ExpressRoute。
先決條件
在開始設定之前,請確認您已符合下列條件。
您有想要連線的虛擬網路。 確認內部部署網路的任何子網路都不會與您要連線的虛擬網路重疊。 若要使用 PowerShell 建立虛擬網路,請參閱 快速入門。
您的虛擬網路沒有任何虛擬網路閘道。 如果您的虛擬網路有閘道 (VPN 或 ExpressRoute),您必須移除所有閘道。 此設定需要將虛擬網路改為連線到虛擬 WAN 中樞閘道。
取得虛擬中樞區域的 IP 位址範圍。 虛擬中樞是由虛擬 WAN 所建立和使用的虛擬網路。 您為虛擬中樞指定的位址範圍不能與您連線的任何現有虛擬網路重疊。 它也不能與您連接到本地的位址範圍重疊。 如果您不熟悉內部部署網路設定中的 IP 位址範圍,請與可以為您提供這些詳細資料的人員協調。
下列 ExpressRoute 線路 SKU 可以連線到中樞閘道:本機、標準和進階。
如果您沒有 Azure 訂閱,請建立免費帳戶。
Azure PowerShell
本文使用 PowerShell Cmdlet。 若要執行 Cmdlet,您可以使用 Azure Cloud Shell。 Cloud Shell 是免費的互動式殼層,可讓您用來執行本文中的步驟。 它具有預先安裝和設定的共用 Azure 工具,可與您的帳戶搭配使用。
若要開啟 Cloud Shell,只要選取程式碼區塊右上角的 [開啟 Cloudshell] 即可。 您也可以移至 https://shell.azure.com/powershell,在另一個瀏覽器索引標籤開啟 Cloud Shell。 選取 [複製] 來複製程式碼區塊,將其貼到 Cloud Shell,然後選取 Enter 鍵來執行。
您也可以在本機電腦上安裝並執行 Azure PowerShell Cmdlet。 PowerShell Cmdlet 會經常更新。 如果您尚未安裝最新版本,指示中指定的值可能會失敗。 若要尋找電腦上安裝的 Azure PowerShell 版本,請使用 Get-Module -ListAvailable Az Cmdlet。 若要安裝或更新,請參閱安裝 Azure PowerShell 模組。
登錄
如果您使用 Azure Cloud Shell,系統會在開啟 Cloudshell 之後,自動將您導向以登入帳戶。 您不需要執行 Connect-AzAccount。 登入之後,您仍然可以視需要使用 Get-AzSubscription 和 Select-AzSubscription 來變更訂用帳戶。
如果您在本機執行 PowerShell,請以提高的權限開啟 PowerShell 主控台,並連線至您的 Azure 帳戶。
Connect-AzAccount Cmdlet 會提示您輸入認證。 您驗證後就會下載您的帳戶設定,以供 Azure PowerShell 使用。 您可以使用 Get-AzSubscription 和 Select-AzSubscription -SubscriptionName "Name of subscription" 來變更訂用帳戶。
建立虛擬 WAN
您必須先建立資源群組來裝載虛擬 WAN 或使用現有的資源群組,才能建立虛擬 WAN。 使用下列其中一個範例。
新增資源群組 - 此範例會在美國西部位置建立名為 testRG 的新資源群組。
建立資源群組。
New-AzResourceGroup -Location "West US" -Name "testRG"建立虛擬 WAN。
$virtualWan = New-AzVirtualWan -ResourceGroupName testRG -Name myVirtualWAN -Location "West US"
現有的資源群組 - 如果您想要在現有的資源群組中建立虛擬 WAN,請使用下列步驟。
設定現有資源群組的變數。
$resourceGroup = Get-AzResourceGroup -ResourceGroupName "testRG"建立虛擬 WAN。
$virtualWan = New-AzVirtualWan -ResourceGroupName testRG -Name myVirtualWAN -Location "West US"
建立虛擬中樞和閘道
使用下列其中一個範例,在新的或現有的虛擬中樞中建立 ExpressRoute 閘道。
新的虛擬中樞 - 此範例會建立名為 westushub 的預設虛擬中樞,其中包含指定的位址前置詞和虛擬中樞的位置。
建立虛擬中樞。
$virtualHub = New-AzVirtualHub -VirtualWan $virtualWan -ResourceGroupName "testRG" -Name "westushub" -AddressPrefix "10.0.0.1/24"建立 ExpressRoute 閘道。 ExpressRoute 閘道會以 2 Gbps 為單位佈建。 1 個縮放單位 = 2 Gbps,最多支援 10 個縮放單位 = 20 Gbps。 虛擬中樞和閘道大約需要 30 分鐘才能完全建立。
$expressroutegatewayinhub = New-AzExpressRouteGateway -ResourceGroupName "testRG" -Name "testergw" -VirtualHubId $virtualHub.Id -MinScaleUnits 2
現有的虛擬中樞 - 此範例會在現有的虛擬中樞中建立 ExpressRoute 閘道。
$expressroutegatewayinhub = New-AzExpressRouteGateway -MaxScaleUnits <UInt32> -MinScaleUnits 2 -Name 'testExpressRoutegw' -ResourceGroupName 'testRG' -Tag @{"tag1"="value1"; "tag2"="value2"} -VirtualHubName "[hub Name]"
建立 ExpressRoute 線路
下一個步驟是取得 ExpressRoute 線路的私人對等互連識別碼。 您可以建立新電路,或從現有電路取得 ID。 使用下列其中一個範例。
新線路 - 此範例會建立新的 ExpressRoute 線路,並取得該線路的私人對等互連識別碼。
$ExpressRouteCircuit = New-AzExpressRouteCircuit -ResourceGroupName "testRG" -Name "testExpressRouteCircuit" -Location "West Central US" -SkuTier Premium -SkuFamily MeteredData -ServiceProviderName "Equinix" -PeeringLocation "Silicon Valley" -BandwidthInMbps 200
Add-AzExpressRouteCircuitPeeringConfig -Name "AzurePrivatePeering" -ExpressRouteCircuit $ExpressRouteCircuit -PeeringType AzurePrivatePeering -PeerASN 100 -PrimaryPeerAddressPrefix "123.0.0.0/30" -SecondaryPeerAddressPrefix "123.0.0.4/30" -VlanId 300
$ExpressRouteCircuit = Set-AzExpressRouteCircuit -ExpressRouteCircuit $ExpressRouteCircuit
$ExpressRouteCircuitPeeringId = $ExpressRouteCircuit.Peerings[0].Id
現有線路 - 此範例會從現有的 ExpressRoute 線路取得詳細資料和私人對等互連識別碼。
$ExpressRouteCircuit = Get-AzExpressRouteCircuit -ResourceGroupName ["resource group name"] -Name ["expressroute circuit name"]
$ExpressRouteCircuitPeeringId = $ExpressRouteCircuit.Peerings[0].Id
將您的電路連接到網關
在本節中,您會將 ExpressRoute (ER) 線路連線到虛擬中樞的 ExpressRoute 閘道。
使用下列其中一個範例來連接您的電路。 這兩個範例都包含選用的授權金鑰步驟。
連線 - 範例 ER 閘道 - 此範例會將您稍早建立的 ExpressRoute 線路連線到虛擬中樞的 ExpressRoute 閘道 ($expressroutegatewayinhub)。
執行下列範例命令:
$ExpressrouteConnection = New-AzExpressRouteConnection -ResourceGroupName $expressroutegatewayinhub.ResourceGroupName -ExpressRouteGatewayName $expressroutegatewayinhub.Name -Name "testConnection" -ExpressRouteCircuitPeeringId $ExpressRouteCircuitPeeringId -RoutingWeight 20
選擇性 - 使用 ExpressRoute 線路的授權金鑰進行連線
建立 ExpressRoute 線路的授權金鑰。 如需步驟,請參閱 如何建立授權。
建立授權之後,取得 ER 線路的授權。
$authorizations = Get-AzExpressRouteCircuitAuthorization -ExpressRouteCircuit $ExpressRouteCircuit取得第一個金鑰的授權金鑰;使用其他金鑰的索引 (亦即 [1])。
$authorizationskey = $authorizationskey[0].AuthorizationKey使用授權金鑰將 ExpressRoute 線路連線到虛擬中樞。
$ExpressrouteConnection = New-AzExpressRouteConnection -ResourceGroupName $expressroutegatewayinhub.ResourceGroupName -ExpressRouteGatewayName $expressroutegatewayinhub.Name -Name "testConnectionpowershellauthkey" -ExpressRouteCircuitPeeringId $ExpressRouteCircuitPeeringId -RoutingWeight 2 -AuthorizationKey $authprizationskey
連線 - 現有的 ER 閘道 - 此範例中的步驟可協助您連線到現有的 ExpressRoute 閘道。
取得現有的虛擬中樞 ExpressRoute 閘道詳細數據。
$expressroutegatewayinhub = Get-AzExpressRouteGateway -ResourceId "[ERgatewayinhubID]"將 ExpressRoute 線路連線到虛擬中樞 ExpressRoute 閘道。
$ExpressrouteConnection = New-AzExpressRouteConnection -ResourceGroupName $expressroutegatewayinhub.ResourceGroupName -ExpressRouteGatewayName $expressroutegatewayinhub.Name -Name "testConnection" -ExpressRouteCircuitPeeringId $ExpressRouteCircuitPeeringId -RoutingWeight 20
選擇性 - 使用 ExpressRoute 線路的授權金鑰進行連線。
建立 ExpressRoute 線路的授權金鑰。 如需步驟,請參閱 如何建立授權。
建立授權之後,取得 ER 線路的授權。
$authorizations = Get-AzExpressRouteCircuitAuthorization -ExpressRouteCircuit $ExpressRouteCircuit取得第一個金鑰的授權金鑰;使用其他金鑰的索引 (亦即 [1])。
$authorizationskey = $authorizationskey[0].AuthorizationKey將 ExpressRoute 線路連線到虛擬中樞 ExpressRoute 閘道。
$ExpressrouteConnection = New-AzExpressRouteConnection -ResourceGroupName $expressroutegatewayinhub.ResourceGroupName -ExpressRouteGatewayName $expressroutegatewayinhub.Name -Name "testConnectionpowershellauthkey" -ExpressRouteCircuitPeeringId $ExpressRouteCircuitPeeringId -RoutingWeight 2 -AuthorizationKey $authprizationskey
測試連線能力
建立線路連線之後,虛擬中樞連線狀態會指出「此中樞」,表示已建立與虛擬中樞 ExpressRoute 閘道的連線。 請等候大約 5 分鐘,然後再測試 ExpressRoute 線路後方用戶端的連線能力,例如您稍早建立的 VNet 中的 VM。
變更閘道大小
在以下的範例中,ExpressRoute 閘道會被調整至不同的規模單位(3 個規模單位)。
Set-AzExpressRouteGateway -ResourceGroupName "testRG" -Name "testergw" -MinScaleUnits 3
後續步驟
接下來,若要深入瞭解虛擬 WAN 中的 ExpressRoute,請參閱: