如何为 Azure Windows VM 重置网络接口How to reset network interface for Azure Windows VM

本文介绍如何重置 Azure Windows VM 的网络接口,以便在执行以下操作后无法连接到 Azure Windows 虚拟机 (VM) 时解决问题:This article shows how to reset the network interface for Azure Windows VM to resolve issues when you cannot connect to Azure Windows Virtual Machine (VM) after:

  • 禁用默认网络接口 (NIC)。You disable the default Network Interface (NIC).
  • 为 NIC 手动设置静态 IP。You manually set a static IP for the NIC.

如果本文未解决你的 Azure 问题,请访问 MSDN 和 CSDN 上的 Azure 论坛。If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and CSDN. 可以在这些论坛上发布问题。You can post your issue in these forums. 还可提交 Azure 支持请求。You also can submit an Azure support request. 若要提交支持请求,请在 Azure 支持页上提交。To submit a support request, on the Azure support page.

重置网络接口Reset network interface

对于部署在资源组模型中的 VMFor VMs deployed in Resource group model

  1. 转到 Azure 门户Go to the Azure portal.

  2. 选择受影响的虚拟机。Select the affected Virtual Machine.

  3. 选择“网络” ,然后选择 VM 的网络接口。Select Networking and then select the network Interface of the VM.

    网络接口位置

  4. 选择“IP 配置” 。Select IP configurations .

  5. 选择 IP。Select the IP.

  6. 如果“专用 IP 分配” 不是“静态” ,则将其更改为“静态” 。If the Private IP assignment is not Static , change it to Static .

  7. 将“IP 地址” 更改为子网中可用的其他 IP 地址。Change the IP address to another IP address that is available in the Subnet.

  8. 虚拟机将重新启动以将新的 NIC 初始化到系统。The virtual machine will restart to initialize the new NIC to the system.

  9. 尝试通过 RDP 连接到计算机。Try to RDP to your machine. 如果成功,可以根据需要将专用 IP 地址更改回原始 IP 地址。If successful, you can change the Private IP address back to the original if you would like. 否则,可以保留它。Otherwise, you can keep it.

使用 Azure PowerShellUse Azure PowerShell

  1. 确保已安装最新的 Azure PowerShellMake sure that you have the latest Azure PowerShell installed

  2. 打开提升的 Azure PowerShell 会话(以管理员身份运行)。Open an elevated Azure PowerShell session (Run as administrator). 运行以下命令:Run the following commands:

    #Set the variables 
    $SubscriptionID = "<Subscription ID>"
    $VM = "<VM Name>"
    $ResourceGroup = "<Resource Group>"
    $VNET = "<Virtual Network>"
    $IP = "NEWIP"
    
    #Log in to the subscription 
    Add-AzAccount -Environment AzureChinaCloud
    Select-AzSubscription -SubscriptionId $SubscriptionId 
    
    #Check whether the new IP address is available in the virtual network.
    Test-AzureStaticVNetIP -VNetName $VNET -IPAddress  $IP
    
    #Add/Change static IP. This process will not change MAC address
    Get-AzVM -ResourceGroupName $ResourceGroup -Name $VM | Set-AzureStaticVNetIP -IPAddress $IP | Update-AzVM
    
  3. 尝试通过 RDP 连接到计算机。Try to RDP to your machine. 如果成功,可以根据需要将专用 IP 地址更改回原始 IP 地址。If successful, you can change the Private IP address back to the original if you would like. 否则,可以保留它。Otherwise, you can keep it.

对于经典 VMFor Classic VMs

重要

经典 VM 将于 2023 年 3 月 1 日停用。Classic VMs will be retired on March 1, 2023.

如果从 ASM 使用 IaaS 资源,请在 2023 年 3 月 1 日之前完成迁移。If you use IaaS resources from ASM, please complete your migration by March 1, 2023. 我们建议你尽快进行切换,以利用 Azure 资源管理器中的许多增强功能。We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.

有关详细信息,请参阅在 2023 年 3 月 1 日之前将 IaaS 资源迁移到 Azure 资源管理器For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.

要重置网络接口,请执行下列步骤:To reset network interface, follow these steps:

使用 Azure 门户Use Azure portal

  1. 转到 Azure 门户Go to the Azure portal.
  2. 选择“虚拟机(经典)” 。Select Virtual Machines (Classic) .
  3. 选择受影响的虚拟机。Select the affected Virtual Machine.
  4. 选择“IP 地址” 。Select IP addresses .
  5. 如果“专用 IP 分配” 不是“静态” ,则将其更改为“静态” 。If the Private IP assignment is not Static , change it to Static .
  6. 将“IP 地址” 更改为子网中可用的其他 IP 地址。Change the IP address to another IP address that is available in the Subnet.
  7. 选择 保存Select Save .
  8. 虚拟机将重新启动以将新的 NIC 初始化到系统。The virtual machine will restart to initialize the new NIC to the system.
  9. 尝试通过 RDP 连接到计算机。Try to RDP to your machine. 如果成功,可以选择将专用 IP 地址重新还原为原始 IP 地址。If successful, you can choose to revert the Private IP address back to the original.

使用 Azure PowerShellUse Azure PowerShell

  1. 确保已安装最新的 Azure PowerShellMake sure that you have the latest Azure PowerShell installed.

  2. 打开提升的 Azure PowerShell 会话(以管理员身份运行)。Open an elevated Azure PowerShell session (Run as administrator). 运行以下命令:Run the following commands:

    #Set the variables 
    $SubscriptionID = "<Subscription ID>"
    $VM = "<VM Name>"
    $CloudService = "<Cloud Service>"
    $VNET = "<Virtual Network>"
    $IP = "NEWIP"
    
    #Log in to the subscription 
    Add-AzureAccount -Environment AzureChinaCloud
    Select-AzureSubscription -SubscriptionId $SubscriptionId 
    
    #Check whether the new IP address is available in the virtual network.
    Test-AzureStaticVNetIP -VNetName $VNET -IPAddress  $IP
    
    #Add/Change static IP. This process will not change MAC address
    Get-AzureVM -ResourceGroupName $CloudService -Name $VM | Set-AzureStaticVNetIP -IPAddress $IP |Update-AzureVM
    
  3. 尝试通过 RDP 连接到计算机。Try to RDP to your machine. 如果成功,可以根据需要将专用 IP 地址更改回原始 IP 地址。If successful, you can change the Private IP address back to the original if you would like. 否则,可以保留它。Otherwise, you can keep it.

删除不可用的 NICDelete the unavailable NICs

通过远程桌面连接到计算机后,必须删除旧的 NIC 以避免出现潜在问题:After you can remote desktop to the machine, you must delete the old NICs to avoid the potential problem:

  1. 打开“设备管理器”。Open Device Manager.

  2. 选择“视图” > “显示隐藏的设备” 。Select View > Show hidden devices .

  3. 选择“网络适配器” 。Select Network Adapters .

  4. 找到名为“Microsoft Hyper-V 网络适配器”的适配器。Check for the adapters named as "Microsoft Hyper-V Network Adapter".

  5. 此时可能会看到灰显的不可用适配器。右键单击该适配器,然后选择“卸载”。You might see an unavailable adapter that is grayed out. Right-click the adapter and then select Uninstall.

    NIC 图像

    备注

    仅卸载名称为“Microsoft Hyper-V 网络适配器”的不可用适配器。Only uninstall the unavailable adapters that have the name "Microsoft Hyper-V Network Adapter". 如果卸载任何其他隐藏的适配器,可能会导致其他问题。If you uninstall any of the other hidden adapters, it could cause additional issues.

  6. 现在,所有不可用的适配器应该都已从系统中清除。Now all unavailable adapters should be cleared of your system.