你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

New-AzVirtualNetworkGatewayConnection

在虚拟网络网关与本地 VPN 设备之间创建站点到站点 VPN 连接。

语法

SetByResource (默认值)

New-AzVirtualNetworkGatewayConnection
    -Name <String>
    -ResourceGroupName <String>
    -Location <String>
    -VirtualNetworkGateway1 <PSVirtualNetworkGateway>
    -ConnectionType <String>
    [-AuthorizationKey <String>]
    [-VirtualNetworkGateway2 <PSVirtualNetworkGateway>]
    [-LocalNetworkGateway2 <PSLocalNetworkGateway>]
    [-RoutingWeight <Int32>]
    [-DpdTimeoutInSeconds <Int32>]
    [-ConnectionMode <String>]
    [-SharedKey <String>]
    [-Peer <PSPeering>]
    [-EnableBgp <Boolean>]
    [-UseLocalAzureIpAddress]
    [-Tag <Hashtable>]
    [-Force]
    [-UsePolicyBasedTrafficSelectors <Boolean>]
    [-IpsecPolicies <PSIpsecPolicy[]>]
    [-TrafficSelectorPolicy <PSTrafficSelectorPolicy[]>]
    [-ConnectionProtocol <String>]
    [-IngressNatRule <PSResourceId[]>]
    [-EgressNatRule <PSResourceId[]>]
    [-GatewayCustomBgpIpAddress <PSGatewayCustomBgpIpConfiguration[]>]
    [-AsJob]
    [-ExpressRouteGatewayBypass]
    [-EnablePrivateLinkFastPath]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

SetByResourceId

New-AzVirtualNetworkGatewayConnection
    -Name <String>
    -ResourceGroupName <String>
    -Location <String>
    -VirtualNetworkGateway1 <PSVirtualNetworkGateway>
    -ConnectionType <String>
    [-AuthorizationKey <String>]
    [-VirtualNetworkGateway2 <PSVirtualNetworkGateway>]
    [-LocalNetworkGateway2 <PSLocalNetworkGateway>]
    [-RoutingWeight <Int32>]
    [-DpdTimeoutInSeconds <Int32>]
    [-ConnectionMode <String>]
    [-SharedKey <String>]
    [-PeerId <String>]
    [-EnableBgp <Boolean>]
    [-UseLocalAzureIpAddress]
    [-Tag <Hashtable>]
    [-Force]
    [-UsePolicyBasedTrafficSelectors <Boolean>]
    [-IpsecPolicies <PSIpsecPolicy[]>]
    [-TrafficSelectorPolicy <PSTrafficSelectorPolicy[]>]
    [-ConnectionProtocol <String>]
    [-IngressNatRule <PSResourceId[]>]
    [-EgressNatRule <PSResourceId[]>]
    [-GatewayCustomBgpIpAddress <PSGatewayCustomBgpIpConfiguration[]>]
    [-AsJob]
    [-ExpressRouteGatewayBypass]
    [-EnablePrivateLinkFastPath]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

说明

在虚拟网络网关与本地 VPN 设备之间创建站点到站点 VPN 连接。

示例

示例 1

$vnetgw1 = Get-AzVirtualNetworkGateway -ResourceGroupName "Rg1" -Name "gw1"
$vnetgw2 = Get-AzVirtualNetworkGateway -ResourceGroupName "Rg1" -Name "gw2"
New-AzVirtualNetworkGatewayConnection -Name conn-client-1 -ResourceGroupName "Rg1" -VirtualNetworkGateway1 $vnetgw1 -VirtualNetworkGateway2 $vnetgw2 -Location "eastus" -ConnectionType Vnet2Vnet -SharedKey 'a1b2c3d4e5'

示例 2 将 IngressNatRule/EgressNatRule 添加到现有虚拟网络网关连接

$vnetgw1 = Get-AzVirtualNetworkGateway -ResourceGroupName "Rg1" -Name "vnetgw1"
$vnetgw2 = Get-AzVirtualNetworkGateway -ResourceGroupName "Rg1" -Name "vnetgw2"
$ingressnatrule = Get-AzVirtualNetworkGatewayNatRule -ResourceGroupName "Rg1" -Name "natRule1" -ParentResourceName vnetgw1
$egressnatrule = Get-AzVirtualNetworkGatewayNatRule -ResourceGroupName "Rg1" -Name "natRule2" -ParentResourceName vnetgw1
New-AzVirtualNetworkGatewayConnection -Name conn-client-1 -ResourceGroupName $RG1 -VirtualNetworkGateway1 $vnetgw1 -VirtualNetworkGateway2 $vnetgw2 -Location "eastus" -ConnectionType Vnet2Vnet -SharedKey 'a1b2c3d4e5' `
-IngressNatRule $ingressnatrule -EgressNatRule $egressnatrule

第一个命令获取名为 natRule1 的虚拟网络网关 natRule,该网关的类型为 IngressSnat。 第二个命令获取名为 natRule2 的虚拟网络网关 natRule,其类型为 EgressSnat。 第三个命令创建此与入口和出口 NatRules 的新虚拟网络网关连接。

示例 3 将 GatewayCustomBgpIpAddress 添加到虚拟网络网关连接

$LocalnetGateway = Get-AzLocalNetworkGateway -ResourceGroupName "PS_testing" -name "testLng"
$gateway = Get-AzVirtualNetworkGateway -ResourceGroupName PS_testing -ResourceName testGw
$address = New-AzGatewayCustomBgpIpConfigurationObject -IpConfigurationId "/subscriptions/83704d68-d560-4c67-b1c7-12404db89dc3/resourceGroups/PS_testing/providers/Microsoft.Network/virtualNetworkGateways/testGw/ipConfigurations/default" -CustomBgpIpAddress "169.254.21.1"

New-AzVirtualNetworkGatewayConnection -ResourceGroupName "PS_testing" -name "Conn" -location "eastus" -VirtualNetworkGateway1 $gateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey abc -GatewayCustomBgpIpAddress $address -EnableBgp $true

这两个命令获取本地网络网关和虚拟网络网关。 第三个命令创建 AzGatewayCustomBgpIpConfigurationObject。 第三个命令使用 GatewayCustomBgpIpAddress 创建新的虚拟网络网关连接。

参数

-AsJob

在后台运行 cmdlet

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-AuthorizationKey

AuthorizationKey。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Confirm

在运行 cmdlet 之前,提示你进行确认。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False
别名:cf

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ConnectionMode

虚拟网络网关连接模式。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ConnectionProtocol

网关连接协议:IKEv1/IKEv2

参数属性

类型:String
默认值:None
接受的值:IKEv1, IKEv2
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-ConnectionType

网关连接类型:IPsec/Vnet2Vnet/ExpressRoute/VPNClient

参数属性

类型:String
默认值:None
接受的值:IPsec, Vnet2Vnet, ExpressRoute, VPNClient
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-DefaultProfile

用于与 Azure 通信的凭据、帐户、租户和订阅。

参数属性

类型:IAzureContextContainer
默认值:None
支持通配符:False
不显示:False
别名:AzContext, AzureRmContext, AzureCredential

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-DpdTimeoutInSeconds

连接的死对等检测超时(以秒为单位)。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-EgressNatRule

与此连接关联的出口 NAT 规则的列表。

参数属性

类型:

PSResourceId[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-EnableBgp

是否通过 S2S VPN 隧道建立 BGP 会话

参数属性

类型:Boolean
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-EnablePrivateLinkFastPath

访问专用链接时绕过 ExpressRoute 网关。 必须启用 ExpressRoute FastPath (ExpressRouteGatewayBypass)。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ExpressRouteGatewayBypass

是否通过绕过网关使用加速虚拟网络访问

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Force

如果想要覆盖资源,请不要要求确认

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-GatewayCustomBgpIpAddress

此连接中使用的虚拟网络网关的 GatewayCustomBgpIpAddress。

参数属性

类型:

PSGatewayCustomBgpIpConfiguration[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-IngressNatRule

与此连接关联的入口 NAT 规则的列表。

参数属性

类型:

PSResourceId[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-IpsecPolicies

IPSec 策略的列表。

参数属性

类型:

PSIpsecPolicy[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-LocalNetworkGateway2

本地网络网关。

参数属性

类型:PSLocalNetworkGateway
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Location

数据库。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Name

资源名称。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False
别名:资源名称

参数集

(All)
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Peer

对等

参数属性

类型:PSPeering
默认值:None
支持通配符:False
不显示:False

参数集

SetByResource
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-PeerId

对等 Id

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

SetByResourceId
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ResourceGroupName

资源组名称。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-RoutingWeight

RoutingWeight。

参数属性

类型:Int32
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-SharedKey

Ipsec 共享密钥。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Tag

表示资源标记的哈希表。

参数属性

类型:Hashtable
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-TrafficSelectorPolicy

流量选择器策略的列表。

参数属性

类型:

PSTrafficSelectorPolicy[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-UseLocalAzureIpAddress

是否为此 S2S VPN 隧道使用 PrivateIP

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-UsePolicyBasedTrafficSelectors

是否对 S2S 连接使用基于策略的流量选择器

参数属性

类型:Boolean
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-VirtualNetworkGateway1

第一个虚拟网络网关。

参数属性

类型:PSVirtualNetworkGateway
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-VirtualNetworkGateway2

第二个虚拟网络网关。

参数属性

类型:PSVirtualNetworkGateway
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-WhatIf

显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False
别名:无线

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

String

PSVirtualNetworkGateway

PSLocalNetworkGateway

Int32

PSPeering

Boolean

SwitchParameter

Hashtable

PSIpsecPolicy

PSTrafficSelectorPolicy

PSGatewayCustomBgpIpConfiguration

输出

PSVirtualNetworkGatewayConnection