New-AzVHubRoute
建立 VHubRoute 物件,以參數的形式傳遞至 New-AzVHubRouteTable 命令。
語法
New-AzVHubRoute
-Destination <String[]>
-DestinationType <String>
-NextHop <String>
-Name <String>
-NextHopType <String>
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
建立 VHubRoute 物件。
範例
範例 1
$rgName = "testRg"
$firewallName = "testFirewall"
$firewall = Get-AzFirewall -Name $firewallName -ResourceGroupName $rgName
New-AzVHubRoute -Name "private-traffic" -Destination @("10.30.0.0/16", "10.40.0.0/16") -DestinationType "CIDR" -NextHop $firewall.Id -NextHopType "ResourceId"
Name : private-traffic
DestinationType : CIDR
Destinations : {10.30.0.0/16, 10.40.0.0/16}
NextHopType : ResourceId
NextHop : /subscriptions/testSub/resourceGroups/testRg/providers/Microsoft.Network/azureFirewalls/testFirewall
上述命令會建立具有 nextHop 的 VHubRoute 對象作為指定的防火牆,然後新增至 VHubRouteTable 資源。
範例 2
$rgName = "testRg"
$hubName = "testHub"
$hubVnetConnName = "testHubVnetConn"
$hubVnetConnection = Get-AzVirtualHubVnetConnection -Name $hubVnetConnName -ParentResourceName $hubName -ResourceGroupName $rgName
New-AzVHubRoute -Name "nva-traffic" -Destination @("10.20.0.0/16", "10.50.0.0/16") -DestinationType "CIDR" -NextHop $hubVnetConnection.Id -NextHopType "ResourceId"
Name : private-traffic
DestinationType : CIDR
Destinations : {10.30.0.0/16, 10.40.0.0/16}
NextHopType : ResourceId
NextHop : /subscriptions/testSub/resourceGroups/testRg/providers/Microsoft.Network/virtualHubs/testHub/hubVirtualNetworkConnections/testHubVnetConn
上述命令會建立具有 nextHop 作為指定 hubVnetConnection 的 VHubRoute 物件,然後新增至 VHubRouteTable 資源。
範例 3
$hub = Get-AzVirtualHub -ResourceGroupName "rgname" -Name "virtual-hub-name"
$hubVnetConn = Get-AzVirtualHubVnetConnection -ParentObject $hub -Name "connection-name"
$hubVnetConn
Name : conn_2
Id : /subscriptions/{subscriptionID}/resourceGroups/{rgname}/providers/Microsoft.Network/virtualHubs/{virtual-hub-name}/hubVirtualNetworkConnections/conn_2
RemoteVirtualNetwork : /subscriptions/{subscriptionID}/resourceGroups/{rgname}/providers/Microsoft.Network/virtualNetworks/rVnet_2
EnableInternetSecurity : True
ProvisioningState : Succeeded
RoutingConfiguration : {
"AssociatedRouteTable": {
"Id": "/subscriptions/{subscriptionID}/resourceGroups/{rgname}/providers/Microsoft.Network/virtualHubs/{virtual-hub-name}/hubRouteTables/defaultRouteTable"
},
"PropagatedRouteTables": {
"Labels": [
"default"
],
"Ids": [
{
"Id":
"/subscriptions/{subscriptionID}/resourceGroups/{rgname}/providers/Microsoft.Network/virtualHubs/{virtual-hub-name}/hubRouteTables/defaultRouteTable"
}
]
},
"VnetRoutes": {
"StaticRoutes": []
}
}
$staticRoute1 = New-AzStaticRoute -Name "static_route1" -AddressPrefix @("10.2.1.0/24", "10.2.3.0/24") -NextHopIpAddress "10.2.0.5"
$routingConfig = $hubVnetConn.RoutingConfiguration
$routingConfig.VnetRoutes.StaticRoutes = @($staticRoute1)
$routingConfig
AssociatedRouteTable : Microsoft.Azure.Commands.Network.Models.PSResourceId
PropagatedRouteTables : {
"Labels": [
"default"
],
"Ids": [
{
"Id":
"/subscriptions/{subscriptionID}/resourceGroups/{rgname}/providers/Microsoft.Network/virtualHubs/rTestHub1/hubRouteTables/defaultRouteTable"
}
]
}
VnetRoutes : {
"StaticRoutes": [
{
"Name": "static_route1",
"AddressPrefixes": [
"10.2.1.0/24",
"10.2.3.0/24"
],
"NextHopIpAddress": "10.2.0.5"
}
]
}
Update-AzVirtualHubVnetConnection -InputObject $hubVnetConn -RoutingConfiguration $routingConfig
上述命令會取得現有 AzVHubRoute 的 RoutingConfiguration,然後在連線上新增靜態路由。 或者,如果您想要建立與靜態路由內的新連線,請參閱這裡的範例 1 。
參數
-DefaultProfile
用於與 Azure 通訊的認證、帳戶、租用戶和訂用帳戶。
類型: | IAzureContextContainer |
別名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Destination
目的地清單。
類型: | String[] |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-DestinationType
目的地的類型。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-Name
路由名稱。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-NextHop
下一個躍點。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |
-NextHopType
下一個躍點類型。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |