使用 Azure PowerShell 重置 ExpressRoute 线路对等互连

本文介绍如何使用 PowerShell 启用和禁用 ExpressRoute 线路的对等互连。 默认情况下,对等互连在创建时处于启用状态。 禁用对等互连后,ExpressRoute 线路的主连接和辅助连接上的 BGP 会话将断开连接。 你会失去此对等互连中与 Microsoft 的连接。 启用对等互连后,ExpressRoute 线路的主连接和辅助连接上的 BGP 会话将建立。 为了进行对等连接,将重新连接到 Azure。 可在 ExpressRoute 线路上单独为 Microsoft 对等互连和 Azure 专用对等互连启用和禁用对等互连。

在两种情况下,你可能会发现重置 ExpressRoute 对等互连很有帮助。

  • 如果想测试灾难恢复设计和实现。 例如,你有两条 ExpressRoute 线路。 可以在一条线路上禁用对等互连,并强制网络流量故障转移到另一条线路。
  • 对 ExpressRoute 线路的 Azure 专用对等互连或 Microsoft 对等互连启用双向转发检测 (BFD)。 如果在 2018 年 8 月 1 日之后创建了 ExpressRoute 线路,且 Microsoft 对等互连是在 2020 年 1 月 10 日之后,则默认对 Azure 专用对等互连启用 BFD。 如果你的线路是在所列日期之前创建的,则需要重置对等互连以启用 BFD。

使用 Azure PowerShell

本文中的步骤和示例使用 Azure PowerShell Az 模块。 若要在计算机上本地安装 Az 模块,请参阅安装 Azure PowerShell。 若要详细了解新 Az 模块,请参阅新 Azure Powershell Az 模块简介。 PowerShell cmdlet 经常更新。 如果未运行最新版本,在说明中指定的值可能无法使用。 若要在系统上查找已安装的 PowerShell 版本,请使用 Get-Module -ListAvailable Az cmdlet。

重置对等互连

  1. 如果在本地运行 PowerShell,请使用提升的权限打开 PowerShell 控制台,然后连接到帐户。 使用下面的示例来帮助连接:

    Connect-AzAccount -Environment AzureChinaCloud
    
  2. 如果有多个 Azure 订阅,请查看该帐户的订阅。

    Get-AzSubscription
    
  3. 指定要使用的订阅。

    Select-AzSubscription -SubscriptionName "Replace_with_your_subscription_name"
    
  4. 运行以下命令,检索 ExpressRoute 线路。

    $ckt = Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"
    
  5. 标识要禁用或启用的对等互连。 对等互连是一个数组。 在以下示例中,Peerings[0] 是 Azure 专用对等互连,而 Peerings[1] 是 Microsoft 对等互连。

    Name                             : ExpressRouteARMCircuit
    ResourceGroupName                : ExpressRouteResourceGroup
    Location                         : chinanorth
    Id                               : /subscriptions/########-####-####-####-############/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit
    Etag                             : W/"cd011bef-dc79-49eb-b4c6-81fb6ea5d178"
    ProvisioningState                : Succeeded
    Sku                              : {
                                      "Name": "Standard_MeteredData",
                                      "Tier": "Standard",
                                      "Family": "MeteredData"
                                    }
    CircuitProvisioningState         : Enabled
    ServiceProviderProvisioningState : Provisioned
    ServiceProviderNotes             :
    ServiceProviderProperties        : {
                                      "ServiceProviderName": "Beijing Telecom Ethernet",
                                      "PeeringLocation": "Beijing",
                                      "BandwidthInMbps": 50
                                    }
    ServiceKey                       : ########-####-####-####-############
    Peerings                         : [
                                      {
                                        "Name": "AzurePrivatePeering",
                                        "Etag": "W/\"cd011bef-dc79-49eb-b4c6-81fb6ea5d178\"",
                                        "Id": "/subscriptions/########-####-####-####-############/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit/peerings/AzurePrivatePeering",
                                        "PeeringType": "AzurePrivatePeering",
                                        "State": "Enabled",
                                        "AzureASN": 12076,
                                        "PeerASN": 123,
                                        "PrimaryPeerAddressPrefix": "10.0.0.0/30",
                                        "SecondaryPeerAddressPrefix": "10.0.0.4/30",
                                        "PrimaryAzurePort": "",
                                        "SecondaryAzurePort": "",
                                        "VlanId": 789,
                                        "MicrosoftPeeringConfig": {
                                          "AdvertisedPublicPrefixes": [],
                                          "AdvertisedCommunities": [],
                                          "AdvertisedPublicPrefixesState": "NotConfigured",
                                          "CustomerASN": 0,
                                          "LegacyMode": 0,
                                          "RoutingRegistryName": "NONE"
                                        },
                                        "ProvisioningState": "Succeeded",
                                        "GatewayManagerEtag": "",
                                        "LastModifiedBy": "Customer",
                                        "Connections": []
                                      },
                                      {
                                        "Name": "MicrosoftPeering",
                                        "Etag": "W/\"cd011bef-dc79-49eb-b4c6-81fb6ea5d178\"",
                                        "Id": "/subscriptions/########-####-####-####-############/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit/peerings/MicrosoftPeering",
                                        "PeeringType": "MicrosoftPeering",
                                        "State": "Enabled",
                                        "AzureASN": 12076,
                                        "PeerASN": 123,
                                        "PrimaryPeerAddressPrefix": "3.0.0.0/30",
                                        "SecondaryPeerAddressPrefix": "3.0.0.4/30",
                                        "PrimaryAzurePort": "",
                                        "SecondaryAzurePort": "",
                                        "VlanId": 345,
                                        "MicrosoftPeeringConfig": {
                                          "AdvertisedPublicPrefixes": [
                                            "3.0.0.3/32"
                                          ],
                                          "AdvertisedCommunities": [],
                                          "AdvertisedPublicPrefixesState": "ValidationNeeded",
                                          "CustomerASN": 0,
                                          "LegacyMode": 0,
                                          "RoutingRegistryName": "NONE"
                                        },
                                        "ProvisioningState": "Succeeded",
                                        "GatewayManagerEtag": "",
                                        "LastModifiedBy": "Customer",
                                        "Connections": []
                                      }
                                    ]
    Authorizations                   : []
    AllowClassicOperations           : False
    GatewayManagerEtag               :
    
  6. 运行以下命令,将对等互连状态更改为“禁用”。

    $ckt.Peerings[0].State = "Disabled"
    Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt
    

    对等互连应处于设定的禁用状态。

  7. 运行以下命令,将对等互连状态更改回“启用”。

    $ckt.Peerings[0].State = "Enabled"
    Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt
    

    对等互连应处于你设定的启用状态。

后续步骤

如果需要帮助排查 ExpressRoute 问题,请参阅以下文章: