[英]Not able to connect through Rasdial in azure ARM VPN connection
我无法使用Powershell cmdlet连接到VPN。 我使用来自构建代理的“ rasdial”连接到vpn,以便我们可以触发自动化测试。 整个过程是自动化的。
先前相同的rasdial命令Rasdial "VPNName"
与vpn的经典模型(ASM)完美配合。 但是,在迁移到ARM之后,我面临着这个问题。 但是,通过UI,即单击按钮以连接到VPN可以正常工作,但我们需要通过脚本进行连接。
我收到一条消息-
该系统不支持此功能。
注意:我正在关注这个帖子-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进行连接。 我希望脚本能做到这一点。
4个月后,我收到了MS的回复(因为我为同一张票出了票)。 他们说,到目前为止,Azure VPN客户端程序包不支持Rasdial。 同样,即使在解构到站点上的天青点VPN之后,仍然缺少添加路由,应该通过显式添加路由来注意这一点。
因此,作为一种解决方法,我执行了博客中提供的步骤-http: //www.diaryofaninja.com/blog/2013/11/27/deconstructing-the-azure-point-to-site-vpn-for-command-line -用法
但是,添加路由的最后一部分有点复杂。 因此,为了添加路线,我创建了自己的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"
此处的xxx是3个八位字节,可在VPN-的“网关-点对点配置”中找到
$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
}
这为我解决了目的。 基本上,您只需要注意路由添加部分。
您的PowerShell脚本看起来不错(我没有尝试登录和资源组的内容,但是其他所有内容都可以从$ fesub开始使用。)除了底部的第三行。 当前作为“ P2SVNETRootCertName”使用的-Name标记必须与$ P2SRootCertName相同。 有关更多信息,请参考Azure文档: https : //azure.microsoft.com/zh-cn/documentation/articles/vpn-gateway-howto-point-to-site-rm-ps/
至于Rasdial,另一个StackOverflow帖子已经回答了这一问题: Azure虚拟网络点对站点(例如Azure Connect)自动连接
-Bridget [MSFT]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.