How to use public static IP with Azure VM

放肆的年华 提交于 2019-12-06 04:50:27

I think you need to create a regional vnet. This worked for me:

1) Get your current Network Config

 Get-AzureVNetConfig -ExportToFile "c:\temp\MyAzNets.netcfg"

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.

You should have something like this:

<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) Send it back into Azure:

Set-AzureVNetConfig -ConfigurationPath "C:\temp\MyAzNets.netcfg"

4) Add/Get your IP in the same location as your vnet.

Get-AzureReservedIP / New-AzureReservedIP

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) 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

You should be able to dynamically assign a reserved IP to a VM (or Cloud Service Web Role) after the VM is created and without any tear down. Works for me. Just do this;

New-AzureReservedIP –ReservedIPName MyReservedIP –Location "East US"

Set-AzureReservedIPAssociation -ReservedIPName MyReservedIP -ServiceName MyVMName

First command reserves the IP. Second command assigns it to the VM. The assignment is immediate and the server will reboot

After many trials with different options in the last two days, finally this worked:

New-AzureVMConfig -Name "mysite" -InstanceSize Basic_A2  -Label "mysite" | Set-AzureSubnet "subnet-1" | add-azureprovisioningconfig -adminusername "myuser" -windows -password "mypwd"|  Add-AzureEndpoint -LocalPort 80 -Name 'HTTP' -Protocol tcp -PublicPort 80 | Add-AzureEndpoint -LocalPort 443 -Name 'HTTPS' -Protocol tcp -PublicPort 443| New-AzureVM -ServiceName "mysite" -ReservedIPName "mysiteip" -Location "East US" -VNetName "mysite"

Don't know why but it did. I had tried this before without any luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!