适用于: ✔️ Windows 虚拟机
总结
本文介绍如何重置Azure Windows VM 的网络接口,以解决在以下情况下无法连接到Microsoft Azure Windows虚拟机(VM)时出现的问题:
- 禁用默认网络接口 (NIC)。
- 为 NIC 手动设置静态 IP。
以下文章还介绍了如何查看和更改 NIC 的设置,这有助于你:
创建、更改或删除网络接口
使用Azure门户、Azure PowerShell或Azure CLI重置 NIC
转到 Azure 门户。
选择受影响的虚拟机。
选择“网络”,然后选择 VM 的网络接口。
选择“IP 配置”。
选择该 IP。
如果专用 IP 分配不是静态,请将其更改为 Static。
将“IP 地址”更改为子网中可用的其他 IP 地址。
虚拟机将重启以初始化系统的新 NIC。
尝试使用 RDP 连接到计算机。 如果成功,可以根据需要将专用 IP 地址更改回原始 IP 地址。 否则你可以保留它。
请确保已安装 最新的 Azure PowerShell。
打开提升的Azure PowerShell会话。 运行以下命令:
#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
虚拟机将重启以初始化系统的新 NIC。
尝试使用 RDP 连接到计算机。 如果成功,可以根据需要将专用 IP 地址更改回原始 IP 地址。 否则你可以保留它。
从Azure门户顶部导航启动 Azure Cloud Shell。
运行以下命令:
az vm repair reset-nic -g MyResourceGroup -n vmName --subscription subscriptionId --yes
或
#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
尝试使用 RDP 连接到计算机。 如果成功,可以根据需要将专用 IP 地址更改回原始 IP 地址。 否则你可以保留它。
删除不可用的网络接口卡 (NIC)
通过远程桌面连接到计算机后,必须删除旧的 NIC 以避免出现潜在问题:
打开设备管理器。
选择“视图”>“显示隐藏的设备”。
选择“网络适配器”。
检查名称为“Microsoft Hyper-V 网络适配器”的适配器。
你可能会看到一个灰色的不可用网络适配器。右键单击该适配器,然后选择“卸载”。
注意
仅卸载名为“Microsoft Hyper-V 网络适配器”的不可用的适配器。 如果卸载任何其他隐藏的适配器,可能会导致其他问题。
现在,所有不可用的适配器应该都已从系统中清除。