Search code examples
azuredynamicipazure-load-balancerazure-public-ip

Azure Public IP scheduled change


I've got an Azure Load Balancer with:

  • Load Balancer fronend IP config: Azure Public IP (dynamic)

  • Load Balancer backend pool: single VM

Is there a way to schedule periodically change of Azure Public IP? Maybe using automation scripts? Or maybe I can create multiple Azure Public IPs and make LB to switch them periodically?


Solution

  • Yes, it is possible. You could use the following example.

    $rgName = "shuilinux"
    $nicName = "shui648"
    $pipName = "shui-ip"
    ##unattach public IP on nic
    $nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName
    $nic.IpConfigurations.PublicIpAddress.Id=""
    $nic|Set-AzureRmNetworkInterface
    
    ##attach public IP to a nic
    ##If you want to create a new Public IP, use $pip = New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic -Force
    $pip = Get-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName
    $nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName
    $nic.IpConfigurations[0].PublicIpAddress = $pip 
    Set-AzureRmNetworkInterface -NetworkInterface $nic