0

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?

AsValeO
  • 2,859
  • 3
  • 27
  • 64

1 Answers1

1

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
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • Thank you very much! Could you please add a code to set DNS name to created IP? – AsValeO Feb 16 '18 at 09:44
  • 1
    For a new public IP, when you create it add `-DomainNameLabel $dnsPrefix`, see this [link](https://learn.microsoft.com/en-us/powershell/module/azurerm.network/new-azurermpublicipaddress?view=azurermps-5.3.0) – Shui shengbao Feb 16 '18 at 09:47
  • 1
    For a existing Public IP, you could use `$pip = Get-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName;$pip.DnsSettings.DomainNameLabel="shuilinux2";$pip|Set-AzureRmPublicIpAddress` – Shui shengbao Feb 16 '18 at 09:49