无法通过 azure ARM VPN 连接中的 Rasdial 进行连接

Not able to connect through Rasdial in azure ARM VPN connection

我无法使用 powershell cmdlet 连接到 VPN。我使用构建代理中的 'rasdial' 连接到 vpn,以便我们可以触发自动化测试。整个过程是自动化的。

之前相同的 rasdial 命令 - Rasdial "VPNName" 与 vpn 的经典模型 (ASM) 完美配合。但是,在我迁移到 ARM 之后,我面临着这个问题。然而,通过 UI 即点击按钮连接到 vpn 工作正常,但我们需要通过脚本连接。

我收到一条消息-

This function is not supported on this system.

注意:我正在关注这个 post- https://dzone.com/articles/deconstructing-azure-point

相同的解决方法在 ASM 中有效,但在 ARM 中无效。有什么方法可以解决这个问题?

我正在使用下面的脚本来创建和下载 VPN 包。我不确定我的脚本中是否遗漏了导致此问题的内容-

$VNetName  = "MYVPN"
$SubName = "Subnet-1"
$GWSubName = "GatewaySubnet"
$VNetPrefix1 = "15.3.0.0/16"
$SubPrefix = "15.3.1.0/24"
$GWSubPrefix = "15.3.200.0/26"
$VPNClientAddressPool = "158.17.201.0/24"
$RG = "VMsRG"
$Location = "West Europe"
$DNS = "15.3.0.0"
$GWName = "GateWay"
$GWIPName = "GateWayIP"
$GWIPconfName = "GateWayIPConfig"
$P2SRootCertName = "XXXXX.cer"
$DeployUserName = "atf@hotmail.com"
$DeployUserPassword = "XXXXX" 

$Azurepwd = ConvertTo-SecureString $DeployUserPassword -AsPlainText -Force
$AzureCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist $DeployUserName, $Azurepwd 
Add-AzureRmAccount -credential $AzureCredential -SubscriptionName Development

New-AzureRmResourceGroup -Name $RG -Location $Location
$fesub = New-AzureRmVirtualNetworkSubnetConfig -Name $SubName -AddressPrefix $SubPrefix
$gwsub = New-AzureRmVirtualNetworkSubnetConfig -Name $GWSubName -AddressPrefix $GWSubPrefix
New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RG -Location $Location -AddressPrefix $VNetPrefix1 -Subnet $fesub, $gwsub -DnsServer $DNS

$vnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RG
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

$pip = New-AzureRmPublicIpAddress -Name $GWIPName -ResourceGroupName $RG -Location $Location -AllocationMethod dynamic

$ipconf = New-AzureRmVirtualNetworkGatewayIpConfig -Name $GWIPconfName -Subnet $subnet -PublicIpAddress $pip

$MyP2SRootCertPubKeyBase64 = "XXXXX"
$p2srootcert = New-AzureRmVpnClientRootCertificate -Name "P2SVNETRootCertName" -PublicCertData $MyP2SRootCertPubKeyBase64
New-AzureRmVirtualNetworkGateway -Name $GWName -ResourceGroupName $RG -Location $Location -IpConfigurations $ipconf -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku Standard -VpnClientAddressPool $VPNClientAddressPool -VpnClientRootCertificates $p2srootcert
Get-AzureRmVpnClientPackage -ResourceGroupName $RG -VirtualNetworkGatewayName $GWName -ProcessorArchitecture Amd64

因为我可以使用 GUI 进行连接。我希望脚本正在完成它的工作。

您的 PowerShell 脚本看起来不错(我没有尝试登录和资源组部分,但从 $fesub 开始其他一切都有效。)除了倒数第三行。您当前作为 "P2SVNETRootCertName" 的 -Name 标签需要与您的 $P2SRootCertName 相同。有关详细信息,请参阅 Azure 文档:https://azure.microsoft.com/en-us/documentation/articles/vpn-gateway-howto-point-to-site-rm-ps/

至于 Rasdial,另一个 Whosebug post 已经回答了这个问题:Azure Virtual Network Point-to-Site (ex. Azure Connect) autoconnect

-布里奇特 [MSFT]

4 个月后,我收到了 MS 的回复(因为我提出了同样的问题)。 他们告诉 Rasdial 到目前为止不受 Azure VPN 客户端包的支持。此外,即使在 deconstructing-the-azure-point-to-site-vpn 之后也没有添加路由,应该通过显式添加路由来注意这一点。

因此,作为解决方法,我执行了博客中提供的步骤 - http://www.diaryofaninja.com/blog/2013/11/27/deconstructing-the-azure-point-to-site-vpn-for-command-line-usage

但是添加路由的最后一部分有点复杂。因此,为了添加路由,我创建了自己的 PS 脚本-

$Subnet                  = @("10.0.1.0", "10.0.2.0","10.0.3.0")
$VPNClientAddressPool    = "x.x.x"  
$Mask                    = "255.255.0.0"
$azureIpAddress          = ""
$VPNCmd                  = "MYVPNName"

这里 x.x.x 是可以在 VPN-"GateWay - Point-to-site configuration" 中找到的 3 个八位字节-

    $routeExists = route print | findstr $VPNClientAddressPool
    if($routeExists) 
    {         
       route delete $Subnet          
    }

    rasdial $VPNCmd > $null
    $azureIPAddress = ipconfig | findstr $VPNClientAddressPool
    if($azureIPAddress -ne $null)
    {   
        $azureIpAddress = $azureIpAddress.Split(": ")
        $azureIpAddress = $azureIpAddress[$azureIpAddress.Length-1]
        $azureIpAddress = $azureIpAddress.Trim()
        route add $Subnet MASK $Mask $azureIPAddress    
    }   

这解决了我的目的。基本上你只需要处理路由添加部分。