This article shows how to reset the network interface for Azure Linux Virtual Machine (VM) to resolve issues when you can't connect to an Azure Linux VM after:
You disable the default network interface (NIC).
You manually set a static IP for the NIC.
The following article also introduces how to view and change settings for a NIC, which might help you:
If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and Stack Overflow. You can post your issue in these forums, or post to @AzureSupport on Twitter. You also can submit an Azure support request. To submit a support request, on the Azure support page, select Get support.
Reset the NIC using Azure portal, Azure PowerShell or Azure CLI
Note
We recommend using the az vm repair reset-nic command to reset the NIC. To run this command, see the following "Azure CLI" tab.
Select Networking and then select the network interface of the VM.
Select IP configurations.
Select the IP.
If the Private IP assignment isn't set to Static, change it to Static.
Change the IP address to another IP address that is available in the Subnet.
The virtual machine restarts to initialize the new NIC to the system.
Try to sign in to your machine using secure shell (SSH). If successful, you can change the Private IP address back to the original if you would like. Otherwise, you can keep it.
Open an elevated Azure PowerShell session. Run the following commands:
#Set the variables
$SubscriptionID = "<Subscription ID>"
$ResourceGroup = "<Resource Group>"
$NetInter="<The Network interface of the VM>"
$VNET = "<Virtual network>"
$subnet= "<The virtual network subnet>"
$PrivateIP = "<New Private IP>"
#You can ignore the publicIP variable if the VM does not have a public IP associated.
$publicIP =Get-AzPublicIpAddress -Name <the public IP name> -ResourceGroupName $ResourceGroup
#Log in to the subscription
Add-AzAccount
Select-AzSubscription -SubscriptionId $SubscriptionId
#Check whether the new IP address is available in the virtual network.
Get-AzVirtualNetwork -Name $VNET -ResourceGroupName $ResourceGroup | Test-AzPrivateIPAddressAvailability -IPAddress $PrivateIP
#Add/Change static IP. This process will change MAC address
$vnet = Get-AzVirtualNetwork -Name $VNET -ResourceGroupName $ResourceGroup
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnet -VirtualNetwork $vnet
$nic = Get-AzNetworkInterface -Name $NetInter -ResourceGroupName $ResourceGroup
#Remove the PublicIpAddress parameter if the VM does not have a public IP.
$nic | Set-AzNetworkInterfaceIpConfig -Name ipconfig1 -PrivateIpAddress $PrivateIP -Subnet $subnet -PublicIpAddress $publicIP -Primary
$nic | Set-AzNetworkInterface
The virtual machine restarts to initialize the new NIC to the system.
Try to use SSH to connect to your machine. If successful, you can change the Private IP address back to the original if you would like. Otherwise, you can keep it.
Launch Azure Cloud Shell from the top navigation of the Azure portal.
Run the following commands:
az vm repair reset-nic -g MyResourceGroup -n vmName --subscription subscriptionId --yes
Or
#Log in to the subscription
az login
az account set --subscription
#Check whether the new IP address is available in the virtual network.
az network vnet check-ip-address -g MyResourceGroup -n MyVnet --ip-address 10.0.0.4
#Add/Change static IP. This process won't change MAC address
az network nic ip-config update -g MyResourceGroup --nic-name MyNic -n MyIpConfig --private-ip-address 10.0.0.9
Try to use SSH to connect to your machine. If successful, you can change the Private IP address back to the original if you would like. Otherwise, you can keep it.