Azure IP Changes

imm2 25 Reputation points
2025-03-09T10:14:40.8066667+00:00

Hello,

I have machine in Azure deployment with NIC which has several IP addresses.

For example:

NIC:

ipconfig1 192.168.10.1 (Private IP) 77.77.77.1(Public IP)

ipconfig2 192.168.10.2 (Private IP) 77.77.77.2(Public IP)

ipconfig3 192.168.10.3 (Private IP) 77.77.77.3(Public IP)

ipconfig4 192.168.10.4 (Private IP) 77.77.77.4(Public IP)

ipconfig5 192.168.10.5 (Private IP) 77.77.77.5(Public IP)

I need to change it very fast in some cases to different Private IP address.

How I can do it with script? because manually it takes a long time.

Also How I can change several IP-s?

I mean just IP-s - ipconfig3,ipconfig4,ipconfig5, but leave ipconfig1 and ipconfig2 as the are?

Please help me, I'm new in azure, but I need to prepare some scripts ASAP,

Thanks in advance,

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,568 questions
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 40,310 Reputation points MVP
    2025-03-09T11:08:26.6066667+00:00

    You can use Azure PowerShell to quickly change the private IP addresses of specific ipconfig settings on your Azure Network Interface Card (NIC). Here's a script that will update only ipconfig3, ipconfig4, and ipconfig5 while leaving ipconfig1 and ipconfig2 unchanged.

    # Define variables
    $ResourceGroupName = "YourResourceGroup"
    $NICName = "YourNIC"
    $NewPrivateIPs = @{
        "ipconfig3" = "192.168.20.3"
        "ipconfig4" = "192.168.20.4"
        "ipconfig5" = "192.168.20.5"
    }
    
    # Get the NIC
    $NIC = Get-AzNetworkInterface -ResourceGroupName $ResourceGroupName -Name $NICName
    
    # Update specific IP configurations
    foreach ($ipconfig in $NewPrivateIPs.Keys) {
        $NIC.IpConfigurations | Where-Object { $_.Name -eq $ipconfig } | ForEach-Object {
            $_.PrivateIpAddress = $NewPrivateIPs[$ipconfig]
        }
    }
    
    # Apply the changes
    Set-AzNetworkInterface -NetworkInterface $NIC
    
    Write-Host "Private IPs updated successfully."
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


0 additional answers

Sort by: Most helpful

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.