適用於:✔️ Linux VM
本文說明如何重設 Azure Linux 虛擬機 (VM) 的網路介面,以解決之後無法連線到 Azure Linux VM 的問題:
- 您停用預設網路介面 (NIC)。
- 您手動設定 NIC 的靜態 IP。
下列文章也介紹如何檢視和變更 NIC 的設定,這可能有助於您:
建立、變更或刪除網路介面
若本文中未提及您的 Azure 問題,請前往 MSDN 及 Stack Overflow 上的 Azure 論壇。 您可以在這些論壇中張貼您的問題,或將問題貼到 Twitter 上的 @AzureSupport。 您也可以提交 Azure 支援要求。 若要提交支援要求,請在 Azure 支援頁面上,選取 [取得支援]。
使用 Azure 入口網站、Azure PowerShell 或 Azure CLI 重設 NIC
前往 Azure 入口網站。
選取受影響的虛擬機器。
選取 [ 網络] ,然後選取 VM 的網络介面。
選取 [IP 設定]。
選取IP。
如果未將 [私人IP指派 ] 設定為 [靜態],請將它變更為 Static。
將 IP位址 變更為子網中可用的另一個IP位址。
虛擬機會重新啟動,以將新的 NIC 初始化至系統。
嘗試使用安全殼層登入您的電腦(SSH)。 如果成功,您可以視需要將私人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 初始化至系統。
嘗試使用 SSH 連線到您的電腦。 如果成功,您可以視需要將私人IP位址變更回原始位址。 否則,您可以保留它。
從 Azure 入口網站 頂端導覽啟動 Azure Cloud Shell。
執行下列命令:
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
嘗試使用 SSH 連線到您的電腦。 如果成功,您可以視需要將私人IP位址變更回原始位址。 否則,您可以保留它。
如果您有疑問,可以詢問 Azure 社群支援。 您也可以向 Azure 意見反應社群提交產品意見反應。