使用 PowerShell 修改本地网络网关设置Modify local network gateway settings using PowerShell

有时本地网络网关 AddressPrefix 或 GatewayIPAddress 的设置会变更。Sometimes the settings for your local network gateway AddressPrefix or GatewayIPAddress change. 本文演示如何修改本地网络网关设置。This article shows you how to modify your local network gateway settings. 还可以选择以下列表中的其他选项,使用另一种方法来修改这些设置:You can also modify these settings using a different method by selecting a different option from the following list:

准备工作Before you begin

安装最新版本的 Azure 资源管理器 PowerShell cmdlet。Install the latest version of the Azure Resource Manager PowerShell cmdlets. 有关安装 PowerShell cmdlet 的详细信息,请参阅 如何安装和配置 Azure PowerShellSee How to install and configure Azure PowerShell for more information about installing the PowerShell cmdlets.

修改 IP 地址前缀Modify IP address prefixes

添加其他地址前缀:To add additional address prefixes:

  1. 设置 LocalNetworkGateway 的变量。Set the variable for the LocalNetworkGateway.

    $local = Get-AzLocalNetworkGateway -Name Site1 -ResourceGroupName TestRG1
    
  2. 修改前缀。Modify the prefixes.

    Set-AzLocalNetworkGateway -LocalNetworkGateway $local `
    -AddressPrefix @('10.101.0.0/24','10.101.1.0/24','10.101.2.0/24')
    

删除地址前缀:To remove address prefixes:

省去你不再需要的前缀。Leave out the prefixes that you no longer need. 在此示例中,我们不再需要前缀 10.101.2.0/24(来自前面的示例),因此需更新本地网关,排除该前缀。In this example, we no longer need prefix 10.101.2.0/24 (from the previous example), so we update the local network gateway, excluding that prefix.

  1. 设置 LocalNetworkGateway 的变量。Set the variable for the LocalNetworkGateway.

    $local = Get-AzLocalNetworkGateway -Name Site1 -ResourceGroupName TestRG1
    
  2. 使用更新的前缀设置网关。Set the gateway with the updated prefixes.

    Set-AzLocalNetworkGateway -LocalNetworkGateway $local `
    -AddressPrefix @('10.101.0.0/24','10.101.1.0/24')
    

修改网关 IP 地址Modify the gateway IP address

如果要连接的 VPN 设备已更改其公共 IP 地址,则需根据该更改修改本地网关。If the VPN device that you want to connect to has changed its public IP address, you need to modify the local network gateway to reflect that change. 修改此值时,还可同时修改地址前缀。When modifying this value, you can also modify the address prefixes at the same time. 请务必使用本地网关的现有名称来覆盖当前设置。Be sure to use the existing name of your local network gateway in order to overwrite the current settings. 如果使用其他名称,请创建一个新的本地网关,而不是覆盖现有的。If you use a different name, you create a new local network gateway, instead of overwriting the existing one.

New-AzLocalNetworkGateway -Name Site1 `
-Location "China North" -AddressPrefix @('10.101.0.0/24','10.101.1.0/24') `
-GatewayIpAddress "5.4.3.2" -ResourceGroupName TestRG1

后续步骤Next steps

可验证网关连接。You can verify your gateway connection. 请参阅验证网关连接See Verify a gateway connection.