question

kimjaeho-8261 avatar image
0 Votes"
kimjaeho-8261 asked AndriyBilous edited

How to change Azure Virtual machine a public Ip address ?

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndriyBilous avatar image
1 Vote"
AndriyBilous answered AndriyBilous edited

Hello @kimjaeho-8261

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://docs.microsoft.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



image.png (190.0 KiB)
image.png (101.8 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I should use the Inside Cloud shell (Power shell) for script configuration?
Can I connect to Azure with my Windows Powershell?

0 Votes 0 ·

142037-image.png


i got it

0 Votes 0 ·
image.png (7.1 KiB)

142013-image.png



  $ip = @{
      Name = 'Weekly'
      ResourceGroupName = 'VM01_group'
      Location = 'eastus2'
      Sku = 'Standard'
      AllocationMethod = 'Static'
      IpAddressVersion = 'IPv4'
      Zone = 1,2,3
  }
  $newPublicIp = New-AzPublicIpAddress @ip
        
  $vnet = Get-AzVirtualNetwork -Name VM01_group-vnet -ResourceGroupName VM01_group
  $subnet = Get-AzVirtualNetworkSubnetConfig -Name default -VirtualNetwork $vnet
  $nic = Get-AzNetworkInterface -Name vm01148 -ResourceGroupName VM01_group
  $nic | Set-AzNetworkInterfaceIpConfig -Name ipconfig1 -PublicIPAddress $newPublicIp -Subnet $subnet
  $nic | Set-AzNetworkInterface

I found this error please recommend

0 Votes 0 ·
image.png (53.1 KiB)
Show more comments
suvasara-MSFT avatar image
1 Vote"
suvasara-MSFT answered

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


Ref: https://docs.microsoft.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.




image.png (104.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.