Associate a Public IP in an Azure Resource Group to a Web App?
Asked Answered
K

1

0

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.

enter image description here

That all looks good (I think, anyway). But in the Portal UI, I see that this IP is not associated to anything:

enter image description here

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

Ketron answered 2/2, 2016 at 21:17 Comment(0)
N
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

  1. Get-something, assign it to a variable.
  2. Change a property of that variable, by assigning some other value.
  3. 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
Noella answered 2/2, 2016 at 23:14 Comment(5)
Ok, thank you for this! This helps fill in a lot of the gaps in my understanding. But, I'm still unclear on one thing: Will this associate the static IP with the web app? (And also, where is $name defined when used in Get-AzureRmNetworkInterface -Name $name)Ketron
@CaseyCrookston it seems my brain went for milk while I was reading your question, and I answered something entirely different. I have included an actual answer this time.Noella
Ok, ignore the last question on my previous comment. I see now that I set $name and $ResourceGroupName to existing values.Ketron
ok ok! Thanks for the update. So, if a web app keeps their incoming and outgoing IP address, how do I find them? I'll poke around and see if I can figure it out.Ketron
Also, your original answer DID help me figure out how to associate a public static IP with a network interface, which thing I did not previously know.Ketron

© 2022 - 2024 — McMap. All rights reserved.