如何使用公共静态IP与Azure的VM [英] How to use public static IP with Azure VM
问题描述
花费几个小时的努力每一个相关的Azure电源外壳命令分配一个虚拟的公网IP到Azure的虚拟机后,我又回到了起点。令人吃惊的是,这样的基本功能不能在Azure中进行。
After spending several hours of trying every relevant Azure Power Shell command to assign a virtual public IP to a Azure VM, I am back to square one. It is amazing that such a basic function cannot be done in Azure.
首先,我保留一个静态IP。然后创建一个虚拟机。然后试图设置azurestaticvnetip。它抱怨subnetnames不能为空。所以,我创建了Azure的门户网站的虚拟网络并创建了一个子网。然后用于设置azuresubnet -subnetnames子网1。现在,抱怨虚拟网络名称不能为空。问题在于没有一个命令序列中取-vnetname作为参数
First, I reserved a static IP. Then create a vm. Then tried set-azurestaticvnetip. It complaint that subnetnames could not be null. So I created a virtual network in Azure portal and created a subnet. Then used set-azuresubnet -subnetnames subnet-1. Now it complaint that virtual network name could not be null. Problem is that none of the commands in the sequence takes -vnetname as a parameter.
然后我发现,这个参数可以在新azurevm传递。所以我删除了(一个不错的解决办法。我是什么高兴我没有花时间在虚拟机配置软件)虚拟机,并尝试使用这个命令来创建。 (此命令中未指定的图像参数。我是进入上提示)。
I then found that this parameter could be passed in new-azurevm. So I deleted (what a nice workaround. i am glad I did not spend time configuring software in the vm) the VM and tried to create using this command. (image parameter is not specified in this command. I was entering that on prompt).
new-azurevmconfig -name myvm -instancesize Basic_A2|
add-azureprovisioningconfig -adminusername "myvmadmin" -windows -password "myvmP123"|
set-azuresubnet -subnetnames subnet-1 |
set-azurestaticvnetip -ipaddress 23.101.39.28 |
new-azurevm -servicename myvm -vnetname mynet –Location "East US" -waitforboot
抛出错误 -
Throws error-
new-azurevm : BadRequest : The static address 23.101.39.28 doesn't belong to the address space defined by the role's subnets.
什么是错在这里?在我看来,这些指令是分配一个专用IP到虚拟机。这是很容易分配静态IP通过Web角色创建的VM(只是把公网IP的名字在配置文件中,这就是它)。我如何分配一个公网IP到VM。微软的文档只是说公网IP,可用于虚拟机,但做了他们认为每个人都知道该怎么做呢?
What is wrong here? Looks to me, these instructions are for assigning a private IP to VM. It is so easy to assign a static IP to a VM created through Web Role (just put public IP name in the config file, thats it). How do I assign a Public IP to a VM. Microsoft documentation merely states that public IP can be used for a VM but did they think everybody would know how to do that?
推荐答案
我认为你需要创建一个区域性的vnet。这为我工作:
I think you need to create a regional vnet. This worked for me:
1)让您当前的网络配置
1) Get your current Network Config
Get-AzureVNetConfig -ExportToFile "c:\temp\MyAzNets.netcfg"
2)打开MyAzNets.netcfg和编辑/(添加?)一个VirtualNetworkSite。我认为,这里的关键是位置,而不是亲合组。您的保留的IP /虚拟机将需要在相同的。
2) Open the MyAzNets.netcfg and edit/(add?) a VirtualNetworkSite. I think the key here is Location and not Affinity Group. Your reserved IP/VM will need to be in the same.
您应该有这样的事情:
<VirtualNetworkSites>
<VirtualNetworkSite name="yourvnet" Location="West US">
<AddressSpace>
<AddressPrefix>192.168.50.0/24</AddressPrefix>
</AddressSpace>
<Subnets>
<Subnet name="yoursubnet">
<AddressPrefix>192.168.50.0/24</AddressPrefix>
</Subnet>
</Subnets>
</VirtualNetworkSite>
</VirtualNetworkSites>
3)发送它放回Azure的:
3) Send it back into Azure:
Set-AzureVNetConfig -ConfigurationPath "C:\temp\MyAzNets.netcfg"
4)添加/获取您的IP中的相同的位置的vnet
4) Add/Get your IP in the same location as your vnet.
Get-AzureReservedIP / New-AzureReservedIP
5)创建虚拟机。
5) Create your VM.
创建或移动虚拟机时,确保云服务不存在。要移动虚拟机只需点击捕捉按钮的管理门户,并给它一个友好的名称,然后同时删除虚拟机和云服务。
When creating or moving a VM make sure the cloud service doesn't exist. To move a VM just hit the capture button in the management portal and give it a friendly name then delete both the VM AND cloud service.
New-AzureVMConfig -Name "my-vm01" -InstanceSize Basic_A2 -ImageName "someimage" -Label "my-vm" | Set-AzureSubnet "**yoursubnet**" | Add-AzureEndpoint -LocalPort 3389 -Name 'RDP' -Protocol tcp -PublicPort 61030 | Add-AzureEndpoint -LocalPort 80 -Name 'HTTP' -Protocol tcp -PublicPort 80 | Add-AzureEndpoint -LocalPort 443 -Name 'HTTPS' -Protocol tcp -PublicPort 443| New-AzureVM -ServiceName "my-vm" -ReservedIPName "**reservedipname**" -Location "West US" -VNetName "**yourvnet**"
6)IP应分配。如果你运行Get-AzureReservedIP现在应该显示是这样的:
6) The IP should be assigned. If you run Get-AzureReservedIP it should now show something like this:
ReservedIPName : reservedipname
Address : 127.0.0.1
Id : xxx
Label :
Location : West US
State : Created
InUse : True
ServiceName : my-vm
DeploymentName : my-vm
这篇关于如何使用公共静态IP与Azure的VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!