Azure CLI 在跨租户配置中添加到 vWan 中心的静态路由 vNet 连接

问题描述 投票:0回答:1

所以我遇到了这种情况,我想弄清楚。我有一个带有 vWan 集线器的租户 A。在此 vWan Hub 中,我有多个 vNet 连接。我添加了来自租户 B (https://learn.microsoft.com/en-us/azure/virtual-wan/cross-tenant-vnet-az-cli) 的新 vNet 连接,它显示为成功一切都很完美。

现在的问题是我需要直接在此 vNet 内添加静态路由(vHub > 虚拟网络连接 > 编辑虚拟网络连接 > 静态路由)。问题是我只能使用 Azure CLI 执行此操作,但我不知道为什么。我尝试过:

az network vhub route create --resource-group YourResourceGroup --vhub-name YourVirtualHub --route-table-name YourRouteTable --destination-prefix 10.0.0.0/24 --next-hop-type VnetLocalGateway --next-hop-ip-address 192.168.1.1

但这会在 vHub 内创建一个我不想要的路由表,我只是希望静态路由直接应用于连接内部。

有人知道允许我在连接内添加此静态路由的 CLI吗?另外,考虑到“下一跳类型”是 Azure 跨租户 vnet - vWan 连接,应该是什么?

谢谢!

az 网络 vhub 路由创建 --resource-group YourResourceGroup --vhub-名称 YourVirtualHub --route-table-name YourRouteTable --destination-prefix 10.0.0.0/24 --next-hop-type VnetLocalGateway --next-hop- IP地址192.168.1.1

它创建了一个我不需要的路由表。

azure command-line-interface azure-cli azure-virtual-network wan
1个回答
0
投票

在我的 Azure 虚拟 WAN 中,我创建了一个没有静态路由的 VNet 连接,如下所示:

enter image description here

要直接在此 VNet 连接内添加静态路由,请使用以下 PowerShell 脚本:

# Define your specific values
$RouteName = "MyRoute"  # Replace with your route name
$DestinationPrefix = "10.0.0.0/24"  # Replace with your destination prefix
$DestinationNVAIPAddress = "192.168.1.1"  # Replace with the IP address of your NVA
$ResourceGroupName = "MyResourceGroup"  # Replace with your resource group name
$VirtualHubName = "MyVirtualHub"  # Replace with your virtual hub name
$VnetConnectionName = "MyVnetConnection"  # Replace with your virtual hub connection name

# Create a static route
$staticRoute = New-AzStaticRoute -Name $RouteName -AddressPrefix $DestinationPrefix -NextHopIpAddress $DestinationNVAIPAddress

# Get the associated and propagated route tables
$associatedTable = Get-AzVHubRouteTable -ResourceGroupName $ResourceGroupName -VirtualHubName $VirtualHubName -Name "defaultRouteTable"
$propagatedTable = Get-AzVHubRouteTable -ResourceGroupName $ResourceGroupName -VirtualHubName $VirtualHubName -Name "noneRouteTable"

# Create a routing configuration with the static route
$updatedRoutingConfiguration = New-AzRoutingConfiguration -AssociatedRouteTable $associatedTable.Id -Label @("testLabel") -Id @($propagatedTable.Id) -StaticRoute @($staticRoute)

# Update the virtual hub's VNet connection with the new routing configuration
Update-AzVirtualHubVnetConnection -ResourceGroupName $ResourceGroupName -VirtualHubName $VirtualHubName -Name $VnetConnectionName -RoutingConfiguration $updatedRoutingConfiguration

输出:

enter image description here

当我检查 Azure 网络连接静态路由时,要在门户中确认已成功添加,如下所示:

enter image description here

参考

如何配置虚拟中心路由:Azure PowerShell - Azure 虚拟 WAN |微软学习

© www.soinside.com 2019 - 2024. All rights reserved.