问题
I'm playing around with Azure Resource Groups.
I've created a group, and in it, I've created a web app. (This is all just academic and I'll delete it all when I'm done leaning, so I don't mind sharing the data.) The web app is located at http://woodswild.azurewebsites.net, and indeed you can go to that address and it will resolve (although there is nothing there, which is fine for now.)
Then, in the same resource group, I also created a Public IP Address that is static.
That all looks good (I think, anyway). But in the Portal UI, I see that this IP is not associated to anything:
Aaannndd.... I'm having a hard time figuring out how to do that. I created the Public IP from within Azure PowerShell with this command:
New-AzureRmPublicIpAddress -AllocationMethod Static -ResourceGroupName TestRG1 -ReverseFqdn woodswild.centralus.cloudapp.azure.com -Name woodswild.azurewebsites.net -Location "Central US" -DomainNameLabel woodswild
According to this article that explains the New-AzureRmPublicIpAddress command, there is no parameter to declare an association. I'm not seeing a way to do it in the Portal UI, and I can't find any answers via Google.
What I'm hoping / wondering / assuming is that once this association is made, you could put the IP Address in a browser and it would resolve to the same place as http://woodswild.azurewebsites.net.
Any ideas? Thanks!!
回答1:
It is not actually possible to assign a static IP address to a Web App. This is because the IP address used by Web Apps isn't used exclusively by you, but instead it is the frontend address pool of the load balancers that sit in front of Azure's Web App service.
However Microsoft do assert that any web app that can have a domain name assigned will keep its external incoming address, and external outgoing addresses for the lifetime of the Web App. This applies to Basic, Standard and Premium SKU. (it might apply to Shared too - I'll have to dig out the doc)
You can find your external incoming IP Address with (yeah, basically, ping it and see what DNS gives!)
Resolve-DnsName (Get-AzureRmWebApp `
-ResourceGroupName $ResourceGroupName -Name $Name).EnabledHostNames[0]
and your external outgoing IP Addresses with
(Get-AzureRmWebApp -ResourceGroupName $ResourceGroupName `
-Name $Name).OutboundIpAddresses
It seems I fell at the first hurdle here, and didn't actually read the question. Or at least my brain seems to have read different words than the ones that are there! (I'll leave the wrong answer here because a, it might be useful to someone, b, I'll likely paste it into an actual answer that it fits one day)
The reason this is so confusing is that it is not instantly obvious the process that Azure uses to update resources.
For the majority of existing resource changes that are made in Azure, the process goes something like
- Get-something, assign it to a variable.
- Change a property of that variable, by assigning some other value.
- Write the change to Azure using the Set-something cmdlet.
In the case of assigning an IP address to a VM, this is the code to use
$ipaddr = New-AzureRmPublicIpAddress -Name test1 `
-ResourceGroupName win10 `
-Location westeurope `
-AllocationMethod Static
$nic = Get-AzureRmNetworkInterface -Name $name `
-ResourceGroupName $ResourceGroupName #1
$nic.IpConfigurations[0].PublicIpAddress = $ipaddr #2
Set-AzureRmNetworkInterface -NetworkInterface $nic #3
来源:https://stackoverflow.com/questions/35163948/associate-a-public-ip-in-an-azure-resource-group-to-a-web-app