How to change Azure Virtual machine a public Ip address ?

kimjaeho 26 Reputation points
2021-10-20T06:36:27.233+00:00

How to change Azure Virtual machine a public Ip address ?
and Do you have a policy or script to change the ip every week?

Azure Network Watcher
Azure Network Watcher
An Azure service that is used to monitor, diagnose, and gain insights into network performance and health.
169 questions
0 comments No comments
{count} vote

Accepted answer
  1. Andriy Bilous 11,421 Reputation points MVP
    2021-10-20T07:39:59.443+00:00

    Hello @kimjaeho

    You can change Azure VM IP address from Azure Portal

    1. Create new Public IP resource in Azure Portal
    2. Select VM resource in Azure Portal
    3. Select Networking in Settings in your VM resource.
    4. In Networking, select the Network interface of the VM. The name of the NIC will be prefixed with the name of the VM and end with a random number.
      142042-image.png
    5. In Settings of the network interface, select IP configurations.
    6. Select ipconfig1 in IP configurations.
      141983-image.png
    7. Select new Public IP address created in step 1 of ipconfig1. and click Save

    https://video2.skills-academy.com/en-us/azure/virtual-network/ip-services/configure-public-ip-vm#change-public-ip-address

    You can create Azure Automation Account and add below script to create new Public IP and associate it with the VM:
    Example:

    $ip = @{  
        Name = '<PublicIPName>'  
        ResourceGroupName = '<ResourceGroupName>'  
        Location = '<Location>'  
        Sku = 'Standard'  
        AllocationMethod = 'Static'  
        IpAddressVersion = 'IPv4'  
        Zone = 1,2,3  
    }  
    $newPublicIp = New-AzPublicIpAddress @ip  
      
    $vnet = Get-AzVirtualNetwork -Name <VirtualNetworkName> -ResourceGroupName <ResourceGroupName>  
    $subnet = Get-AzVirtualNetworkSubnetConfig -Name <VMSubnetName> -VirtualNetwork $vnet  
    $nic = Get-AzNetworkInterface -<VMNicName> -ResourceGroupName <ResourceGroupName>  
    $nic | Set-AzNetworkInterfaceIpConfig -Name ipconfigName -PublicIPAddress $newPublicIp -Subnet $subnet  
    $nic | Set-AzNetworkInterface  
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. suvasara-MSFT 10,041 Reputation points
    2021-10-20T07:23:59.71+00:00

    @kimjaeho , Changing Public IP address of an Azure VM can be achieved by altering the NIC IP configuration.
    141899-image.png

    Ref: https://video2.skills-academy.com/en-us/azure/virtual-network/ip-services/configure-public-ip-vm#change-public-ip-address

    Yes, you can use your custom script to change the PIP on a weekly basis. For PowerShell use these set commands in your automation,

    Set-AzNetworkInterfaceIpConfig

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.